IT lexicon › Programming › The ABA problem

The ABA problem

Programming På svenska → Updated: 2026-07-29

A thread reads the value A, gets interrupted, and when it returns the value is A again — but in between it was B, and the world is not the same.

This is the classic trap in lock-free programming. Compare-and-swap compares only the value, not the history, so the operation succeeds and the thread believes nothing happened. In a lock-free stack it looks like this: the thread reads the top node, another thread pops it, frees the memory, allocates a new node that happens to land at the same address and pushes it. The first thread's CAS sees the same pointer value, succeeds, and links in a successor that no longer exists. The mitigations are either a tagged pointer where a version counter is incremented on every write and compared in the same operation, or deferring reuse of the memory — hazard pointers, epoch-based reclamation or RCU.

← Back to the lexicon