Connecting Tech Pros Worldwide Help | Site Map

Is std::queue thread-safe?

Andy
Guest
 
Posts: n/a
#1: Jul 23 '05
Hi,

Is std::queue thread-safe, or shall I use some synchronization
facilities such as pthread_mutex to make sure my usage is thread-safe?

Thanks!

- Andy

red floyd
Guest
 
Posts: n/a
#2: Jul 23 '05

re: Is std::queue thread-safe?


Andy wrote:[color=blue]
> Hi,
>
> Is std::queue thread-safe, or shall I use some synchronization
> facilities such as pthread_mutex to make sure my usage is thread-safe?
>
> Thanks!
>
> - Andy
>[/color]

Compiler dependent.
Panjandrum
Guest
 
Posts: n/a
#3: Jul 23 '05

re: Is std::queue thread-safe?


Andy wrote:[color=blue]
> Is std::queue thread-safe, or shall I use some synchronization
> facilities such as pthread_mutex to make sure my usage is thread-safe?[/color]

Depends on your usage. If you want multiple threads to read from/add to
the queue than you must, of course, synchronize access. BTW, not even
Java collections are locked down by default.

Me
Guest
 
Posts: n/a
#4: Jul 23 '05

re: Is std::queue thread-safe?


> Is std::queue thread-safe, or shall I use some synchronization[color=blue]
> facilities such as pthread_mutex to make sure my usage is thread-safe?[/color]

The C++ standard doesn't say anything about threads. As with any C++
extension, check your compiler's documentation. I highly suggest you
consider using lock/wait free data structures instead, even if you
don't get the benifit of having an STL container class:

http://en.wikipedia.org/wiki/Lock-fr...ree_algorithms
http://appcore.home.comcast.net/
http://www.cs.chalmers.se/~noble/
http://www.cl.cam.ac.uk/Research/SRG/netos/lock-free/

Closed Thread