Is STL queue Thread Safe?

Discussion in 'C++' started by Sriram Rajagopalan, Nov 11, 2004.

  1. Hi,

    Are STL queues thread safe in the scenario below:

    I have 2 threads, one pushing to the rear end of the STL queue.. then
    posting a semaphore- The other thread waits for the semaphore and would
    access the front of the queue. The semaphore is initialized to 0.

    Is there a possiblity of race condition in the above scenario?

    Thanks,
    Sriram.
    Sriram Rajagopalan, Nov 11, 2004
    #1
    1. Advertising

  2. "Sriram Rajagopalan" <> wrote in message
    news:cmveo6$ogs$...
    > Hi,
    >
    > Are STL queues thread safe in the scenario below:
    >
    > I have 2 threads, one pushing to the rear end of the STL queue.. then
    > posting a semaphore- The other thread waits for the semaphore and would
    > access the front of the queue. The semaphore is initialized to 0.
    >
    > Is there a possiblity of race condition in the above scenario?
    >
    > Thanks,
    > Sriram.
    >


    C++ standard makes no mentions of threads at all. So whether your STL is
    thread safe depends entirely on the implementation. Consult your
    documentation.

    john
    John Harrison, Nov 11, 2004
    #2
    1. Advertising

  3. "Sriram Rajagopalan" <> wrote in message news:<cmveo6$ogs$>...
    > Hi,
    >
    > Are STL queues thread safe in the scenario below:
    >
    > I have 2 threads, one pushing to the rear end of the STL queue.. then
    > posting a semaphore- The other thread waits for the semaphore and would
    > access the front of the queue. The semaphore is initialized to 0.


    Please be more specific:
    What are you using as semaphore?

    >
    > Is there a possiblity of race condition in the above scenario?
    >
    > Thanks,
    > Sriram.


    C++ does not deal with threads, currently there are many on-going
    discussions in c.l.c++.m.
    By this nothing of the STL is thread-safe.

    If you properly control the access to the queue with a semaphore
    then yes, it is thread safe.

    regards,
    Stephan Brönnimann

    Open source rating and billing engine for communication networks.
    Stephan Br?nnimann, Nov 11, 2004
    #3
    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. Bram Stolk
    Replies:
    0
    Views:
    393
    Bram Stolk
    May 19, 2004
  2. Russell Warren

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

    Russell Warren, Jun 22, 2006, in forum: Python
    Replies:
    4
    Views:
    678
    Russell Warren
    Jun 27, 2006
  3. Gabriel Rossetti
    Replies:
    0
    Views:
    1,310
    Gabriel Rossetti
    Aug 29, 2008
  4. Kris
    Replies:
    0
    Views:
    477
  5. John Nagle
    Replies:
    5
    Views:
    463
    John Nagle
    Mar 12, 2012
Loading...

Share This Page