Deadlock

Deadlock is a state where tasks wait on each other forever and no task can make progress.

Intuition

Each participant holds something another participant needs, so everyone is stuck.

Technical definition

Deadlock arises when conditions such as mutual exclusion, hold-and-wait, no preemption, and circular wait occur together.

Example

Thread A holds lock 1 and waits for lock 2 while thread B holds lock 2 and waits for lock 1.

Common misunderstandings

  • Deadlock is different from slow performance.
  • Adding more locks can increase deadlock risk.

Need this inside a product?

The studio builds the systems these terms describe. Tell us what you are working on.