how can I make a queue thread safe? I need to push / pop / front / back and clear. is there something similar in boost?
I have one producer and one or more consumer.
You must protect access to std::queue
. If you are using boost protect it using boost::mutex
. Now if you have multiple readers and one writer thread look at boost::shared_lock
(for readers) and boost::unique_lock
(for writer).
However if you will encounter writer thread starvation look at boost::shared_mutex
.