CS FundamentalsVery hardGATE CS

compare_and_swap(&v, expected, new) atomically sets v = new only if v == expected and returns the old value. A lock-free increment is written as `do { old = v; } while (CAS(&v, old, old + 1) != old);`. Which problem can affect CAS-based algorithms on pointers (e.g. a lock-free stack)?

  1. A. Deadlock between two CAS loops
  2. B. Priority inversion caused by CAS
  3. C. The ABA problem: a value changes from A to B and back to A, so CAS wrongly succeeds
  4. D. CAS cannot be implemented on multiprocessors

Correct answer: C. The ABA problem: a value changes from A to B and back to A, so CAS wrongly succeeds

CAS only checks equality, not history. If a node is popped, freed and a new node is allocated at the same address, a stale CAS succeeds and corrupts the structure; tagged pointers or hazard pointers fix it.

More Operating Systems questions

Exams that ask this topic