Is STL queue Thread Safe?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sriram Rajagopalan

    Is STL queue Thread Safe?

    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.


  • John Harrison

    #2
    Re: Is STL queue Thread Safe?


    "Sriram Rajagopalan" <sriram@mot.com > wrote in message
    news:cmveo6$ogs $1@newshost.mot .com...[color=blue]
    > 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.
    >[/color]

    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


    Comment

    • Stephan Br?nnimann

      #3
      Re: Is STL queue Thread Safe?

      "Sriram Rajagopalan" <sriram@mot.com > wrote in message news:<cmveo6$og s$1@newshost.mo t.com>...[color=blue]
      > 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.[/color]

      Please be more specific:
      What are you using as semaphore?
      [color=blue]
      >
      > Is there a possiblity of race condition in the above scenario?
      >
      > Thanks,
      > Sriram.[/color]

      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
      broeni@osb-systems.com
      Open source rating and billing engine for communication networks.

      Comment

      Working...