In fact, it is completely pointless to indicate X
whether or not it is thread safe! You have to pick up for what kinds of uses. For example, it is unlikely that any class will be "thread safe" when it is somehow used in one thread and destroyed in another.
However, the statement that std::vector<T>
not thread safe, regardless of how often it repeats, is false . However, it seems that most people do not understand and do not appreciate the provided guarantees of thread safety. std::vector<T>
is thread safe in the following sense:
- You can read a vector object from several streams at the same time.
- If there is one thread modifying a vector object, there should be neither simultaneous readers, nor writers.
- Access to the vector object does not interfere with other vector objects.
This applies to the vector structure itself. Access to the contained object is tied to any rules imposed on them. This, apparently, is not a guarantee of thread safety, which many people have in mind, but something stronger will not work with the container interface.
source share