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

Under the 'out-of-thin-air' (OOTA) problem, why does the standard place a special restriction on relaxed atomics involving self-justifying dependency cycles?

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