Pre*_*rag 1 c++ multithreading race-condition c++11
由于没有解决这个问题的一部分,我将它作为一个单独的问题:
#include<iostream>
#include<thread>
using namespace std;
void f2(double* ret) {
*ret=5.;
}
int main() {
double ret=0.;
thread t2(f2, &ret);
t2.join();
cout << "ret=" << ret << endl;
}
Run Code Online (Sandbox Code Playgroud)
这个节目数据是否免费比赛?
对于新的C++内存模型,是否有任何保证可以同步ret从线程t2和线程访问变量main?
我的意思是,如果程序在同一个核心上执行,很明显访问t2和main不会发生冲突.
但是,如果t2和main在不同内核上执行?
在main继续执行之前,是否有任何保证核心缓存会同步?
如果有人能提供相同的参考资料我会很感激.
谢谢.