Intermediate Topic 28 of 51 Concurrency & Parallelism
ABA Problem
Hazard when a value changes and changes back unnoticed.
How it works
The ABA problem occurs in lock-free algorithms using compare-and-swap: a thread reads a value A from a location, is delayed, meanwhile other threads change the value to B and then back to A, and when the first thread's CAS compares and sees A, it succeeds, wrongly assuming nothing has changed, though the underlying state may be different. In a lock-free stack, a popped node may be freed and reallocated at the same address with different contents, corrupting the structure.
Where it is used
Lock-free stacks, queues and memory allocators encounter the ABA problem, which also appears in database optimistic concurrency checks based on values.
Common pitfall
Solutions include version counters or tagged pointers combined with the pointer in a double-width CAS, hazard pointers and epoch-based reclamation that prevent reuse of memory while it may be referenced, load-linked and store-conditional instructions that detect any write, and garbage-collected languages where addresses are not reused while referenced. Remember that equal values are not equal histories.
Where it fits in the course
ABA Problem is topic 28 of 51 in Concurrency & Parallelism, rated Intermediate. It follows Wait-Free Algorithms. The next topic is Software Transactional Memory.
Practice and explore
- Open the interactive lesson, with a mini quiz.
- Take the Concurrency & Parallelism quiz.
How to study this topic
- Read the explanation above and restate the definition in your own words.
- Open the interactive lesson and answer its mini quiz.
- Read the common pitfall, then write a short example that avoids it.
- Check your understanding in the Concurrency & Parallelism quiz, and revisit the topic if you miss a question.
Frequently asked questions
What is ABA Problem?
Where do people use ABA Problem?
What is the most common mistake with ABA Problem?
What should I learn before this topic?
How can I practice it?
Is ABA Problem hard to learn?
How long does it take to learn ABA Problem?
Which topics are related to ABA Problem?
What should I study after ABA Problem?
Related topics
- Wait-Free Algorithms (Concurrency & Parallelism)
- Software Transactional Memory (Concurrency & Parallelism)
- Lock-Free Data Structures (Concurrency & Parallelism)
- Data Parallelism (Concurrency & Parallelism)
- Consensus Problem (Distributed Systems & Cloud)
- Knapsack Problem (Algorithms)
- N-Queens Problem (Algorithms)