is < vector > threadsafe for read/write at different locations?

Viewed 2971

this is a beginner question i guess but i couldn't find the answer to this particular question:

i have a standard (c++) vector v of size 10 and type int.

is it safe to have a thread alter all the even positions (v.at(0) = x; v.at(2) = y; etc.) and another thread alter all the values for the odd positions (v.at(1) = a; v.at(3)=b;etc.) at the same time?

so, no changing of size, no push_back() etc. during the lifetime of these 2 threads.

if it is not safe, would the use of an array be a better way to do this?

thanks for your help.

5 Answers
Related