I know that is possible to read concurrently from a std::vector
without "bad" consequences because this operation can be considered thread-safe.
But the same cannot be said for writing operations. But, I am wondering if this is not always true, for example considering my particular scenario.
I have a std::vector<bool>
, where all the elements are initialized to false
, and, given an array of indices, I need to change the value of these elements (vector[index]
for each index) from false
to true
.
If I use a different thread for each index (and there is the possibility that some indices have the same value), can this operation be considered thread-safe?
If the vector is a std::vector<int>
(or any primitive type) and the value assigned is always the same (for example 1) can this operation still be considered thread-safe?