STL Not Thread-Safe

I've heard this mentioned multiple times, but I have no idea what people mean when they say it. Anyone care to enlighten me?
One cannot safely access a container when it may be modified in another thread. Any number of threads can safely access a const (read-only) container. And a single thread can safely modify a container that it and only it owns.
Is there any particular reason for this? Would locking a mutex help if editing from another thread was needed?
NGen yes it would. One of the reasons they are not thread safe is so you can optimize them to the program so that they don't have to keep locking them all the time. Particularly if its only used in one thread. No one wants to lock the a container if its not being used across threads.

In many cases you can avoid locking by understanding how the particular algorithm your using on the container works.
Last edited on
Alright, thanks for that.
You can use TBB library.
http://www.opentbb.org

There are many algorithms to parallize loops, sinc objects and etc.

And there are thread safe container.

For example tbb::concurrent_vector
Topic archived. No new replies allowed.