All challenges
Code AnalysisHard 60s

Relaxed store publish bug

What is the bug?
Starter code
int data = 0; std::atomic<bool> ready{false};
// producer:
data = 42;
ready.store(true, std::memory_order_relaxed);
// consumer:
while(!ready.load(std::memory_order_relaxed)) {}
assert(data == 42);

Think you can answer under pressure?

Get matched and answer live questions in 3-minute 1v1 battles. Elo ranking, badge tiers and bragging rights on the line.

Play this in a 3-minute battle