我读过这个,我的问题很相似但有点不同.
注意,我知道C++ 0x并不能保证这一点,但我特别要求像x86-64这样的多核机器.
假设我们有2个线程(固定到2个物理内核)运行以下代码:
// I know people may delcare volatile useless, but here I do NOT care memory reordering nor synchronization/
// I just want to suppress complier optimization of using register.
volatile int n;
void thread1() {
for (;;)
n = 0xABCD1234;
// NOTE, I know ++n is not atomic,
// but I do NOT care here.
// what I cares is whether n can be 0x00001234, i.e. in the middle of the update from core-1's …Run Code Online (Sandbox Code Playgroud)