Code Room
Code reviewHardcr-g421
Subject Race conditionsLevel Senior–Staff~34 minCommon in Concurrency interviewsIndustries Software development

Question

Review this C++ lock-free free-list. `pop` hands out a node; `push` returns one. Multiple threads call both.

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
std::atomic<Node*> head; Node* pop() {  Node* old = head.load();  while (old &&         !head.compare_exchange_weak(old, old->next)) {}  return old;} void push(Node* n) {  n->next = head.load();  while (!head.compare_exchange_weak(n->next, n)) {}}
Run or narrate your approach, then ask the coach.