What actually happens when I make a thread and pass a vector reference to it which i fill in the thread. example : let say I have a function that takes a vector reference and adds numbers to it. and i thread that function into two threads. is the acces to the passed vector somehow coordinated or is there a possibility ffor two threads to write to the same location in that vector:
Code:
void Func(vector<int>& xx){
for(...)
xx.push_back(i);
}
void main(){
threads ...
vec ...
for (int i = 0; i < 2; ++i)
threads.push_back(thread(Func, ref(vec)));
for(auto &t : threads)
t.join();
}
will two threads sinc their access and push back or is it up to me to do that ??
thnx
PS the above is a form of pseudo-code