Is STL queue Thread Safe?

S

Sriram Rajagopalan

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

John Harrison

Sriram Rajagopalan said:
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
 
S

Stephan Br?nnimann

Sriram Rajagopalan said:
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
(e-mail address removed)
Open source rating and billing engine for communication networks.
 

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

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top