AlgoViz

Deadlocks and lock order

hard 65 min

Two threads, two locks, and a program that waits for ever.

Chapter mnemonic

Four conditions for deadlock

One key each. Keep yours. No snatching. Wait in a ring.

If all threads acquire keys in the same global order, which deadlock condition is prevented?

Circular wait. A chain that acquires keys in increasing order cannot close into a ring.