Code RoomFree list ABA problem
HardPrep Room Coding #2049

Free list ABA problem

Code reviewConcurrencySenior–Staff~34 min

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.

0:00 of about 34 min
Mark a line and say what kind of problem it is.0 findings
1std::atomic<Node*> head;
2 
3Node* pop() {
4 Node* old = head.load();
5 while (old &&
6 !head.compare_exchange_weak(old, old->next)) {}
7 return old;
8}
9 
10void push(Node* n) {
11 n->next = head.load();
12 while (!head.compare_exchange_weak(n->next, n)) {}
13}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.