Re: Thread safe vector class



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


.



Relevant Pages

  • Re: filewatcher question
    ... I guess I can get the file watcher change event to just queue up the file ... Furthermore the file watcher changed event will do a quick look up if the ... I will also have to look up thread safe GUI as well ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Thread safe queue in C
    ... within linux with C and i need a thread safe queue.How can i obtain a ... Anyway, creating a queue with POSIX Threads is rather trivial, I don't see why you can't quickly create one: ... typedef struct queue_s queue; ... queue* const _this, ...
    (comp.programming.threads)
  • VS 2008 / net framework 3.0 3.5 / wpf - Dispatcher-Methods not thread safe
    ... Any instance members are not guaranteed to be thread safe. ... this means in the worker threads I would call for exampel ... I had to synchronise each call of Dispatcher.Invoke. ... for the purpose of marshaling from different threads. ...
    (microsoft.public.dotnet.framework)
  • Re: STL Queue
    ... > In the STL documentation, it says that a queue is not thread safe. ... > Thread A will "push" stuff onto a queue. ...
    (microsoft.public.win32.programmer.ui)
  • STL Queue
    ... In the STL documentation, it says that a queue is not thread safe. ... Thread A will "push" stuff onto a queue. ...
    (microsoft.public.win32.programmer.ui)