Priority inversion: a high-priority task H is blocked waiting for a mutex held by low-priority task L. A medium-priority task M is runnable. The scheduler runs M (it's higher priority than L), starving L, which means H never gets the mutex. H is blocked indefinitely by M, which it nominally has higher priority than.

Priority inheritance solution: when L holds a mutex that H is waiting for, temporarily boost L's priority to H's priority. L finishes and releases the mutex. H runs. L returns to its original priority.

Simple in concept. The implementation in Rust took 4 redesigns.

Redesign 1 — Naive: Mutex stores owner task ID and waiter list. On contention, boost owner. Problem: the borrow checker won't let you hold a mutable reference to the scheduler while also mutating task state through the mutex. Two mutable borrows of overlapping data.

Redesign 2 — Interior mutability: Wrap scheduler state in RefCell. Compiles. Problem: RefCell panics if you borrow twice. In interrupt context, a nested interrupt can trigger a double borrow — runtime panic in a safety-critical kernel. Unacceptable.

Redesign 3 — Split ownership: Separate the ready bitmap from the task priority fields. The mutex only touches priority fields (via a separate UnsafeCell with manual proof of single-access). The scheduler only touches the bitmap. No overlap. Works, but UnsafeCell requires you to prove the safety invariants manually. Written as explicit comments in the kernel — the unsafe contract.

Redesign 4 — Final: A PriorityToken type that can only be created by the scheduler, passed into the mutex lock call, and consumed on release. The type system proves that priority modification only happens through the scheduler's controlled path. Zero unsafe, zero RefCell, borrow checker satisfied.

The lesson: when the borrow checker fights you on concurrent state, it is usually right. The final design is cleaner and more obviously correct than the first three attempts.