CS FundamentalsVery hardGATE CS · Amazon/Microsoft SDE MCQ

A lock-free stack pops with CAS(&top, old, old->next). Thread 1 reads top = A (A->next = B) and is delayed; thread 2 pops A, pops B, then pushes A back. Thread 1's CAS now succeeds. What is wrong?

  1. A. Nothing, because CAS guarantees the stack stays consistent
  2. B. The CAS keeps failing forever, so the threads livelock
  3. C. Top becomes B, a node no longer in the stack (the ABA problem)
  4. D. Thread 1 pops A twice, so the stack gains a duplicate node

Correct answer: C. Top becomes B, a node no longer in the stack (the ABA problem)

CAS checks only that top still equals A, not that the stack is unchanged. Thread 1 installs its stale A->next = B, re-linking a freed node. Tagged pointers (version counters) or hazard pointers avoid ABA.

More Operating Systems questions

Exams that ask this topic