Questions / Quant development, Concurrency & coordination
Locks acquired in opposite order
Worker A holds X and waits for Y; worker B holds Y and waits for X. Neither times out. How many of the two workers can make progress?
Answer it in the app It's free. You get hints, a second try if you miss, and a follow-up question.
Show the answer and worked solution
Answer: 0 workers
- A needs Y, which only B can release.
- B needs X, which only A can release.
- Each waits on the other forever, so neither progresses: a deadlock.
Interview shortcut. Circular wait: zero progress.
Takeaway. A circular wait stops every participant.
In the app this has a follow-up where one thing about the setup changes. Try the follow-up.