Arule for all standard containers is:
- Many readers or one writer on the entire container and on each element.
- Individual element reading or modification (not adding/removing an element) is also read operation on the container.
That is only modestly too strong. You can do a small number of things that violate the above rules without being a race condition under the standard.
In the standard, this is usually worded in terms of const
methods on the container. A read method is const
, a write method is not const
. The exception is that begin()
and end()
and data()
(methods that just return iterators) that are non-const
count as const
.
For iteration and element access, it is worded in terms of iterator invalidation. Many operations invalidate iterators, and if an iterator is invalidated in an unsequenced manner with its use it is a race condition.
As an example of a case where the rule of thumb above says "no" but the standard says "ok":
You can have a map and a reference to a value in the map stored. You can be editing the value while another thread adds key value pairs to the map.
As no iterators are invalidated by the map, and you aren't touching the key, I beleive there is no race condition.