Is std::queue thread-safe?

Discussion in 'C++' started by Andy, Jul 5, 2005.

  1. Andy

    Andy Guest

    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
     
    Andy, Jul 5, 2005
    #1
    1. Advertising

  2. Andy

    red floyd Guest

    Andy wrote:
    > 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.
     
    red floyd, Jul 5, 2005
    #2
    1. Advertising

  3. Andy

    Panjandrum Guest

    Andy wrote:
    > 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.
     
    Panjandrum, Jul 5, 2005
    #3
  4. Andy

    Me Guest

    > 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/
     
    Me, Jul 6, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sriram Rajagopalan

    Is STL queue Thread Safe?

    Sriram Rajagopalan, Nov 11, 2004, in forum: C++
    Replies:
    2
    Views:
    6,349
    Stephan Br?nnimann
    Nov 11, 2004
  2. Russell Warren

    Is Queue.Queue.queue.clear() thread-safe?

    Russell Warren, Jun 22, 2006, in forum: Python
    Replies:
    4
    Views:
    712
    Russell Warren
    Jun 27, 2006
  3. Gabriel Rossetti
    Replies:
    0
    Views:
    1,376
    Gabriel Rossetti
    Aug 29, 2008
  4. Kris
    Replies:
    0
    Views:
    517
  5. John Nagle
    Replies:
    5
    Views:
    495
    John Nagle
    Mar 12, 2012
Loading...

Share This Page