M
M
Mikhail Konyukhov2014-11-06 08:45:53
C++ / C#
Mikhail Konyukhov, 2014-11-06 08:45:53

STL queue - thread-safe for push/pop?

If push() of a new element is executed in one thread, and in another

if (!queue.empty()){
  element = queue.first();
  queue.pop();
}

do i need to use mutex or can push/pop be done without mutex?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DancingOnWater, 2014-11-06
@piromanlynx

All STL containers are not thread safe unless otherwise noted. The reason is simple - the inevitable loss of performance in cases where thread safety is not needed.
Remember C++ is made for the developer's freedom of choice. Take a break from this.

A
AxisPod, 2014-11-06
@AxisPod

No, of course, if necessary, you can look at boost::lockfree or Intel TBB. Well, either close it yourself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question