Learn the vocabulary of two threads each waiting forever on a lock the other one holds.
0 / 5 completed
1 / 5
At standup, a dev mentions thread A holding lock 1 while waiting on lock 2, and thread B holding lock 2 while waiting on lock 1, so neither thread ever makes progress again. What is this situation called?
A deadlock is exactly this: thread A holds lock 1 and waits on lock 2, while thread B holds lock 2 and waits on lock 1, so each is blocked forever on a resource the other refuses to release. A livelock is a related but distinct failure where threads keep responding to each other's state changes without ever actually blocking, yet still never progress. This circular-wait condition is the textbook definition of a deadlock, and it's why acquiring more than one lock at a time is inherently risky without a shared discipline.
2 / 5
During a design review, the team wants every thread in the codebase to acquire locks 1 and 2 in the same global order, never the reverse, specifically to make deadlock structurally impossible. Which capability supports this?
Enforcing a consistent global lock-acquisition order makes a circular wait structurally impossible, since if every thread always acquires lock 1 before lock 2, no thread can ever be found holding lock 2 while waiting on lock 1. Letting each thread pick its own order is exactly what allows two independently written code paths to deadlock the moment they happen to disagree. This ordering discipline is one of the standard, low-cost techniques for eliminating an entire category of deadlock by design rather than detecting it after the fact.
3 / 5
In a code review, a dev notices one function acquires lock A then lock B, while a different function elsewhere in the same module acquires lock B then lock A. What does this represent?
This is exactly a lock-ordering violation that risks a future deadlock, since if these two functions ever run concurrently and each grabs its first lock before the other releases theirs, both will block waiting on the other's second lock forever. A cache eviction policy is an unrelated concept about discarding cached data. This kind of reversed-order acquisition is precisely the subtle bug a reviewer needs to catch before two rarely-concurrent code paths happen to collide in production.
4 / 5
An incident report shows a production service hung completely, and a thread dump revealed two threads each waiting on a lock the other one held, because two independently written modules acquired the same pair of locks in opposite orders. What practice would prevent this?
Enforcing a single consistent lock-acquisition order across every code path removes the circular-wait condition a deadlock depends on, and a timed try-lock with backoff gives a thread a way to detect contention and retry instead of blocking forever if ordering slips through anyway. Continuing to let different code paths pick their own order is exactly what caused the hang described in this incident. This combination of ordering discipline and defensive timeouts is the standard defense once a deadlock has actually reached production.
5 / 5
During a PR review, a teammate asks why the team documents and enforces a global lock-acquisition order instead of trusting each module's author to simply avoid acquiring conflicting locks. What is the reasoning?
Two modules can each be perfectly correct on their own, yet still deadlock the instant they're combined if one happens to acquire lock A then B while the other acquires B then A, since neither author had visibility into the other's ordering choice. A documented global order removes that risk by construction, because no thread can ever hold the second lock in a pair while waiting on the first. The tradeoff is the ongoing discipline of actually following and reviewing for that documented order as the codebase grows and more modules start touching the same locks.