Hacker News new | ask | show | jobs
by a1369209993 976 days ago
> The rule for mutexes is, never take more than one.

Ideally the actual rule is, never take a mutex while holding another mutex. You can take multiple mutexes simultaneously if the API supports it. (The problem is the API usually doesn't support it unless you implement the mutexes yourself using lower-level primitives, but that requires not actually using mutexes as your primitive.)

( > the technical rule is always take mutexes in the same order.

As you note, this doesn't actually work in practice, since you've given youself the opprotunity to get the order wrong every single time you do it.)