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

Two threads run concurrently on x and y, both initially 0. With these exact orderings, is it possible for both r1 and r2 to read 0 (i.e., store buffering observed)?

std::atomic<int> x{0}, y{0}; int r1, r2; // Thread 1: x.store(1, std::memory_order_relaxed); r1 = y.load(std::memory_order_relaxed); // Thread 2: y.store(1, std::memory_order_relaxed); r2 = x.load(std::memory_order_relaxed);