there. I want to test the code below.
atomic<int> x(0);
atomic<int> y(0);
void thr1()
{
x.store(1,memory_order_relaxed);
y.store(1,memory_order_relaxed);
}
void thr2()
{
while(!y.load(memory_order_relaxed))
;
cout<<x.load(memory_order_relaxed)<<endl; //may 0 or 1
}
I know the output may be 0.
However, no matter how much times I tried, I always get 1.
Is this because of my CPU is x86 architecture?
If not, how to fix this problem?
(BTW, I know CppMem. But it cannot use loop.)
Aucun commentaire:
Enregistrer un commentaire