Dealing With Contention hard
The ABA problem occurs in lock-free CAS algorithms when:
- A Threads deadlock.
- B Value A changes to B, then back to A. A thread reading A thinks nothing changed, but the underlying state (e.g., pointer to a freed node) has changed, leading to corruption.
- C Memory leaks.
- D Stack overflow.
Answer: B. Value A changes to B, then back to A. A thread reading A thinks nothing changed, but the underlying state (e.g., pointer to a freed node) has changed, leading to corruption.
Common in Lock-Free stacks. Solved by double-wide CAS or versioned pointers (A1 -> B2 -> A3).
One system design question a day, with spaced repetition so the ones you miss come back.
Get the appRelated questions
- Why is 'Exponential Backoff' preferred over constant intervals for retries?
- What is the primary purpose of a Mutex (Mutual Exclusion) lock?
- Why does adding more threads sometimes *decrease* performance?
- In a Saga, if a Compensating Transaction (Undo) fails repeatedly due to contention, what is the last resort?
- In a database, what happens if Transaction A locks a row and Transaction B tries to modify the same row?
- A database restart causes thousands of application servers to instantly try to reconnect. This crashes the DB again. This is called: