How Two Waiting Workers Can Deadlock

A cycle of waiting can prevent participants from reaching the releases that would let others proceed.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace a benign example
  2. Check ordering in the design
  3. Draw the cycle before choosing an ordering rule
  4. Check every path that acquires those resources

Trace a benign example

Worker one holds A and requests B. Worker two holds B and requests A. Neither reaches its normal release. A prerequisite cycle gives a graph representation of the waits.

Check ordering in the design

A consistent acquisition order avoids this two-lock pattern when every participating path respects it. Apply the rule at the resource interface. See consistent lock acquisition.[1]

Draw the cycle before choosing an ordering rule

Worker A owns lock X and asks for Y. Worker B owns Y and asks for X. Under blocking acquisition with neither releasing its first lock, both wait. Requiring a common order for tasks needing both rules out this two-lock cycle. See consistent database lock ordering.

A holds X → waits for Y
B holds Y → waits for X
Common order X then Y avoids opposite first acquisitions

Check every path that acquires those resources

An uncommon error or callback path can use another ordering. Test with bounded waits and controlled schedules. Confirm that locks are released when a worker raises or returns early.

References

  1. OpenMP Architecture Review Board, OpenMP API Specifications ↩