Kernel: Dealing with deadlocks in unix

你说的曾经没有我的故事 提交于 2021-01-27 13:46:38

问题


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?


回答1:


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.




回答2:


No, the order can't be changed by the OS. The phrase should be read as: "if the programmer is sensible and locks resources in the same order across all competing entities, many deadlocks will be impossible".



来源:https://stackoverflow.com/questions/13658645/kernel-dealing-with-deadlocks-in-unix

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!