Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Is STL queue Thread Safe?

Reply
Thread Tools

Is STL queue Thread Safe?

 
 
Sriram Rajagopalan
Guest
Posts: n/a
 
      11-11-2004
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.


 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      11-11-2004

"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


 
Reply With Quote
 
 
 
 
Stephan Br?nnimann
Guest
Posts: n/a
 
      11-11-2004
"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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Program blocked in Queue.Queue.get and Queue.Queue.put Kris Python 0 01-04-2012 03:46 PM
why does the following with Queue, q.put('\x02', True) not put itin the queue? Gabriel Rossetti Python 3 04-25-2008 03:41 PM
Is Queue.Queue.queue.clear() thread-safe? Russell Warren Python 4 06-27-2006 03:03 PM
what's the difference between #include "queue.h" and #include "queue.cpp" Kceiw C++ 3 03-14-2006 03:01 AM
Queue.Queue-like class without the busy-wait Paul L. Du Bois Python 29 04-04-2005 01:28 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57