<queue> queue threadsafe?
-
Hi, I speak of the class std::queue / #include In my case the question is: 1. Is it safe to execute
m_queue.push
from thread A, while thread B executesm_queue.pop
? 2. Is it safe to executem_queue.push
from thread A, while thread B executesm_queue.empty
? 3. Is it safe to executem_queue.push
from thread A and also from thread B? I hope you understand what i mean, thanks in advance Snow. -
Hi, I speak of the class std::queue / #include In my case the question is: 1. Is it safe to execute
m_queue.push
from thread A, while thread B executesm_queue.pop
? 2. Is it safe to executem_queue.push
from thread A, while thread B executesm_queue.empty
? 3. Is it safe to executem_queue.push
from thread A and also from thread B? I hope you understand what i mean, thanks in advance Snow. -
None of the STL objects are thread safe. Wrap the calls in critical sections. Tim Smith I'm going to patent thought. I have yet to see any prior art.
Thanks for your answer Tim. I found an MSDN article "Thread Safety in the Standard C++ Library" which statet that some of the STL container classes are threadsafe (but only in certain cases). But I think it will be better to write a wrapper for the queue class as you wrote before. It seems to be the only way to be on the safe side. Thanks, Snow.