Relaxed atomics lose memory ordering
Review this C++ publish/consume flag pattern.
The atomic is there so it must be fine, right?
What a strong answer looks like
Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.
0:00 of about 40 min
Mark a line and say what kind of problem it is.0 findings
1int payload = 0;
2std::atomic<bool> ready{false};
3
4void producer() {
5 payload = compute(); // (1) plain store
6 ready.store(true, std::memory_order_relaxed); // (2)
7}
8
9void consumer() {
10 while (!ready.load(std::memory_order_relaxed)) {} // (3) spin
11 use(payload); // (4)
12}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.
Run or narrate your approach, then ask the coach.