Code Room
Code reviewMedium
Question
Review this C++ reference-counted handle. `release()` is called from multiple threads when handles go out of scope.
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.
Learn the concepts
struct Resource { std::atomic<int> refs{1}; Data* data; void acquire() { refs.fetch_add(1, std::memory_order_relaxed); } void release() { if (refs.fetch_sub(1, std::memory_order_relaxed) == 1) { delete data; data = nullptr; } }};Run or narrate your approach, then ask the coach.