Unix – Kernel: Dealing with deadlocks in unix

deadlocklinux-kernelunix

A deadlock would occur if process 1 locks resource A and waits for
resource B, while simultaneously (due to context switches at the "right" places) process 2 locks resource B and waits for access to resource
A
.

How does Unix deal with such deadlocks? I read the following here.

Many deadlocks can be prevented by simply requiring all processes that
lock multiple resources to lock them in the same order (e.g.,
alphabetically by lock name)

How can it change the order in which locks are acquired without also changing the execution order?
Could someone detail the approach to deadlock-handling taken by the modern Unix kernel?

Best Answer

For Linux kernel, it does NOT handle this, because it has no idea on how to fix it. Instead, it detects this kind of deadlock at runtime and complains.

The technology it uses is lockdep, which is a runtime locking correctness validator, for details, please take a look at kernel document Documentation/lockdep-design.txt.

Related Topic