Code Room
Code reviewHardcr-g225
Subject Memory orderingLevel Senior–Staff~40 minCommon in Code quality & review interviewsIndustries Software development

Question

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.

Talk through your review
Code to reviewcpp
int   payload = 0;std::atomic<bool> ready{false}; void producer() {    payload = compute();                              // (1) plain store    ready.store(true, std::memory_order_relaxed);     // (2)} void consumer() {    while (!ready.load(std::memory_order_relaxed)) {}  // (3) spin    use(payload);                                      // (4)}
Run or narrate your approach, then ask the coach.