LDD3: Chapter 5
image source
Be careful not to double lock! e.g. foo() gets lock A, calls bar() which also gets lock A Common solution: modified _bar() that assumes A is already held
Total ordering! if you lock A then B then C You MUST unlock C then B then A And never lock B then A (etc) somewhere else! Otherwise, you get deadlock…