Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardC++atomics and memory orderingSingle-choice MCQ

Given the classic message-passing pattern below with `data` non-atomic and `ready` atomic, which memory orderings on the store and load are the minimum needed so the reader is guaranteed to observe `data == 42`?

int data = 0; std::atomic<bool> ready{false}; // Producer: data = 42; ready.store(true, /*order?*/); // Consumer: while (!ready.load(/*order?*/)) {} assert(data == 42);