System deadlocks (1971):死锁产生的四个必要条件
站着说话不腰疼的教科书:
不能称为是一个合理的 argument
四个条件中最容易达成的
Lock ordering
Textbooks will tell you that if you always lock in the same order, you will never get this kind of deadlock.
The best locks are encapsulated: they never get exposed in headers, and are never held around calls to non-trivial functions outside the same file. You can read through this code and see that it will never deadlock, because it never tries to grab another lock while it has that one. People using your code don't even need to know you are using a lock.
—— Unreliable Guide to Locking by Rusty Russell