Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardC++relaxed memory semanticsSingle-choice MCQ

Consider relaxed atomics. Two threads execute the code below; `x` and `y` start at 0 and all operations use `memory_order_relaxed`. Which combination of printed results is permitted by the C++ memory model that would be forbidden if every operation used `memory_order_seq_cst`?

// x, y are atomic<int>, init 0 // Thread 1: // Thread 2: x.store(1, relaxed); y.store(1, relaxed); int r1 = y.load(relaxed); int r2 = x.load(relaxed); // print r1, r2