Flag Without A Fence
int payload = 0; // plain int
std::atomic<bool> ready{false};
void producer() {
payload = 42;
ready.store(true, std::memory_order_relaxed);
}
void consumer() {
while (!ready.load(std::memory_order_relaxed)) { }
assert(payload == 42); // fires on ARM; on x86 the compiler may still sink the payload store
}
Which single change makes the assertion hold on every platform?
Sign in to answer questions and track your progress
Sign In