Deadlock and Global Lock Ordering

Identify a wait cycle and prove why acquiring locks in a consistent strict order prevents that cycle.

Source
Anbloq
Language
English
Created
Updated
Chapters
2
Reading time
1 min
In this article2 chapters
  1. A waiting thread can hold what another needs
  2. A strict order rules out circular acquisition

A waiting thread can hold what another needs

If thread A holds lock one while waiting for lock two, and thread B holds lock two while waiting for lock one, each needs an action blocked by the other. Represent waiting as directed dependencies. Under exclusive single ownership of these locks and no external preemption, the cycle stops both threads from completing their lock acquisitions.

A strict order rules out circular acquisition

Assign each lock a rank and require a thread acquiring more locks to request only higher-ranked ones while holding lower ones. Along any hypothetical cycle, ranks would have to strictly increase back to the starting rank, impossible. The rule needs to cover callbacks, helper functions and dynamically chosen resources. It addresses one kind of deadlock, not all progress or fairness questions. Mutex invariants determine which locks must be held. Progress conditions distinguish system-wide and per-operation progress.[1]

References

  1. Remzi H. Arpaci-Dusseau and Andrea C. Arpaci-Dusseau, Operating Systems: Three Easy Pieces ↩