Questions / Quant development, Concurrency & coordination

Locks acquired in opposite order

Applied, about 6 minutes. Question D017.

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

  1. A needs Y, which only B can release.
  2. B needs X, which only A can release.
  3. 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.

More concurrency & coordination questions