Both Read Zero
Two threads run once each on an x86-64 machine, with mo the same ordering everywhere:
std::atomic<int> X{0}, Y{0};
int r1, r2;
// thread 1 // thread 2
X.store(1, mo); Y.store(1, mo);
r1 = Y.load(mo); r2 = X.load(mo);
With mo = std::memory_order_relaxed, a harness that repeats this in a loop observes r1 == 0 && r2 == 0 roughly once every 6,600 trials. Changing mo to std::memory_order_seq_cst makes that outcome disappear entirely. What did seq_cst change on this machine?
Sign in to answer questions and track your progress
Sign In