Is std::queue thread-safe?

A

Andy

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
 
R

red floyd

Andy said:
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

Compiler dependent.
 
P

Panjandrum

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

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.
 
M

Me

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

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-free_and_wait-free_algorithms
http://appcore.home.comcast.net/
http://www.cs.chalmers.se/~noble/
http://www.cl.cam.ac.uk/Research/SRG/netos/lock-free/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top