I'm working with C++11 on a project and here is a function:
void task1(int* res) {
*res = 1;
}
void task2(int* res) {
*res = 2;
}
void func() {
std::vector<int> res(2, 0); // {0, 0}
std::thread t1(task1, &res[0]);
std::thread t2(task2, &res[1]);
t1.join();
t2.join();
return res[0] + res[1];
}
The function is just like that. You see there is a std::vector, which store all of the results of the threads.
My question is: can std::vector cause false sharing? If it can, is there any method to avoid false sharing while using std::vector to store the results of threads?