Is using std::deque or std::priority_queue thread-safe?

From Scott Myer's Effective STL Item 12. Have realistic expectations about the thread safety of STL containers

Multiple readers are safe. Multiple threads may simultaneously read the contents of a single container, and this will work correctly. Naturally, there must not be any writers acting on the container during the reads.

Multiple writers to different containers are safe. Multiple threads may simultaneously write to different containers.

When it comes to thread safely and STL containers, you can hope for a library implementation that allows multiple readers on one container and multiple writers on separate containers. You can't hope for the library to eliminate the need for manual concurrency control, and you can't rely on any thread support at all.


The STL does not provide any guarantees for thread safety. This is especially the case when modifying the same container from multiple threads.

The implementation of the STL that you're using may provide some level of thread safety, but you would need to look at the documentation for your implementation.