xv6DeadlockAvoid - ccc-sp/riscv2os GitHub Wiki

xv6: 如何設計才不會發生死結?

使用 lock ordering 可以避免死結,但有時 ordering 會很難確保!

6.4 Deadlock and lock ordering

To avoid such deadlocks, all code paths must acquire locks in the same order. The need for a global lock acquisition order means that locks are effectively part of each function’s specification: callers must invoke functions in a way that causes locks to be acquired in the agreed-on order.

Honoring a global deadlock-avoiding order can be surprisingly difficult. Sometimes the lock order conflicts with logical program structure,