Re: Unfair C++ bashing
from: https://embeddedartistry.com/blog/2017/8/2/an-overview-of-c-stl-containers
Standard Container Thread Safety
I want to share with you some relevant points regarding container thread safety, as many embedded systems will likely require sharing objects across threads. The following general thread-safety rules apply:
All container functions are safe to be called concurrently on different objects of the same container type (i.e. it is safe to use two different std::vector instances on two different threads
All const member functions can be called concurrently by different threads
Containers can be safely read from multiple threads if no thread is making asynchronous writes
Different elements in the same container can be modified concurrently, except for the elements of std::vector<bool>.
If an object is written to by one thread and read by other threads, the object must be protected
In general, iterator operations read from a container, but do not modify it, so they are thread-safe
Container operations that invalidate iterators are NOT thread-safe, as they modify the container
The most important detail to keep in mind: if you are modifying the container in multiple threads, you will need to protect that container to prevent concurrent access. For more information using containers in a thread-safe way, see Implementing a Thread-Safe Queue using Condition Variable
Also, Boost provides a selection of lock-free container alternatives which you can consider for multi-threaded use cases.