T0003 nested-locks¶
Rule: No second lock is taken while a guard is alive.
| Code | T0003 (stable, never reused) |
| Id | nested-locks |
| Category | state |
| Source | spirit_level |
| Fix | by hand |
Level per tier¶
| Tier | Level | Reason |
|---|---|---|
| small | off | |
| small-workspace | warn |
two locks at once need one lock order everywhere |
| medium | warn |
two locks at once need one lock order everywhere |
| big | warn |
two locks at once need one lock order everywhere |
| ai | off | |
| embedded | off | |
| ui | off | |
| egui | off | |
| units-strict | off | |
| units-paranoid | off |
Why¶
Taking a second lock while holding one creates a lock order that every other path must follow; one path that takes them the other way deadlocks. tpm's turn engine split its state over 16 mutexes and took several at once.
How to fix¶
Put both pieces of state under one owner, or take the locks one after the other with the first guard dropped in between.
Configure¶
Allow one finding in the code with // spirit-level: allow(nested-locks) <reason> (waivers); the code works there too, as in [lints.T0003].