Parallel reads should be fine, but parallel writes or parallel reads and writes can cause problems.
It is right. This is a guarantee generally offered for unsynchronized access to objects in C ++. Such "problems" are formally called data races.
Now I learned that at www.cplusplus.com access to or change of the list during most of the operations is safe.
No, containers do not offer more than a basic guarantee for concurrent readings. There will be a data race if one thread accesses it and the other modifies it. However, in some containers it is sometimes safe to access the elements of the container while the container itself is modified.
The first example says that find does not change the value of the container or access element (keys only), therefore it is safe if it is accessed by other threads, or by changing (different) values ββwithout changing the container itself.
The second example means that you can safely access an existing element (using a link or an iterator to this element), since inserting an element will not interfere with the existing one.
I ask for C ++, not for C ++ 11
Nowadays, C ++ is C ++ 11. If you ask about historical versions of the language, they had nothing to say about threads, so the question does not answer at all, only for the specific implementation and structure of the threads.
Mike seymour
source share