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

Given the code below with `x` and `y` initially 0 and all stores/loads using `memory_order_relaxed`, can the assertion fail under the C++ memory model?

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