Skip to content
StackDecode
System Design
16. Performance EngineeringAnimated

Deadlock Prevention

Avoid circular waits.

The idea

Acquire locks in a fixed order, use timeouts, or avoid holding multiple locks.

Watch it work

Press play, pause, or step through. Some animations have settings you can change.

Txn 1Row ARow BTxn 2lock A
  • current message
  • earlier
  • failure or attack

Txn 1 locks row A.

step:
1/6
from:
Txn 1
to:
Row A
1/6

Time runs downward. Solid arrows are requests, dashed arrows are replies.

Step by step

  1. 1Define a global lock order
  2. 2Acquire in that order
  3. 3Use timeouts
  4. 4Detect and retry

Where it is used

Concurrent code.

Watch out for

Order violations appear in rare paths.

Related