Re: Thread safe vector class
- From: "Carl Daniel [VC++ MVP]" <cpdaniel_remove_this_and_nospam@xxxxxxxxxxxxxxx>
- Date: Mon, 30 Jan 2006 08:09:06 -0800
Jim Langston wrote:
> "Jim Langston" <tazmaster@xxxxxxxxxxxxxx> wrote in message
> news:0%dDf.332$Q%3.5@xxxxxxxxxxx
>> I'm looking for a thread safe vector class for windows. Using
>> Microsoft Visual C++ .net 2003.
>>
>> If I can't find one I'll have to make and and it's a little bit
>> beyond me right now, but I'm plugging away at it anyway.
>>
>> Anyone know of one?
>
> It seems I need to provide more detail with what I'm looking for
> since 2 people asked.
>
> The specific case I want it for right now is for a message queue
> between worker threads and the main thread. It would be one way
> communication, that is, the worker threads add messages
> (std::strings) with push_back() and the main thread retrieves the
> messages.
> This would seem to be rather trivial just by wrapping a vector in a
> class and having the class only give access to the specific methods
> needed for this queue. push_back, [] (or is that (), not sure what
> to overload for []) and a few others.
>
> But then I was thinking if I go ahead and do this, I might as well
> make it usable for all data types, meaning it now needs to become a
> template rather than a wrapper class. Which is no longer trivial. So I
> was hoping someone already wrote one.
OK, what you're looking for isn't a threadsafe vector, but a
producer/consumer queue (which might be built internally on a vector).
Try this one out:
http://www.codeproject.com/threads/semaphores.asp
If that one doesn't fit your needs, Google for "thread safe producer
consumer queue" and you'll get dozens of hits.
-cd
.
- References:
- Thread safe vector class
- From: Jim Langston
- Re: Thread safe vector class
- From: Jim Langston
- Thread safe vector class
- Prev by Date: Re: Thread safe vector class
- Next by Date: Direct3D and ATL window
- Previous by thread: Re: Thread safe vector class
- Next by thread: Compiler can't see class
- Index(es):
Relevant Pages
|
|