The idea: give every resource a priority of its own
Real-time scheduling shows priority inversion with one mutex and how priority inheritance fixes it: the job holding the lock runs at the priority of the job it blocks. With more than one resource, inheritance is not enough. A high-priority job can be blocked once by every lower job, and two jobs that lock in opposite orders can still deadlock. The priority ceiling protocols fix both. Each resource gets a ceiling: the highest priority of any task that uses it. The ceilings are known before the system runs, so the scheduler can refuse a lock that might cause trouble later.
The page runs three jobs on one CPU with fixed priorities H = 3, M = 2 and L = 1 (higher wins). A job is a list of ticks of work and lock and unlock steps; R1[3] means "hold R1 for 3 ticks". A red cell means the job is ready but a lower-priority job runs: that is blocking, and the "blocked" column counts it. A yellow cell is normal waiting for a higher job.
Chained blocking under inheritance
In scenario A, L locks R1 at tick 1, M preempts it and locks R2 at tick 3, and H arrives at tick 4 needing R1 and then R2. With no protocol, H blocks on R1 and M, which does not even use R1, runs ahead of it: H waits 5 ticks, and a longer M would make it wait longer (Demo: no protocol, unbounded inversion). With inheritance, L runs at priority 3 until it unlocks R1 (ticks 5–6), then H runs, asks for R2, and M has to finish its section at priority 3 (tick 8). H was blocked twice, once by each lower job: 3 ticks here, and up to 3 + 2 = 5 in the worst case (Demo: inheritance, chained blocking). With n lower jobs, H can be blocked n times.
The deadlock inheritance allows
In scenario B, L locks R1 and then R2 inside it, while H locks R2 and then R1: the opposite order. L takes R1 at tick 1. H arrives at tick 2, preempts L and takes R2, which is free. At tick 3 H asks for R1 and blocks; L inherits priority 3, runs, asks for R2 and blocks too. Each waits for the other forever (Demo: inheritance, deadlock with nested locks). Inheritance changes who runs, not who holds what, so it cannot break the cycle. Lock order deadlock shows the same cycle between two threads, and deadlock detection shows how a system finds one after the fact.
The original priority ceiling protocol
Sha, Rajkumar and Lehoczky (1990) added one rule to inheritance: a job may lock a resource only if its priority is higher than the ceilings of all resources currently locked by other jobs. If not, it blocks, and the job holding that resource inherits its priority. In scenario A, M asks for R2 at tick 3. R2 is free, but L holds R1 with ceiling 3, and M's 2 is not above 3: refused. So when H arrives, only L is in its way. H is blocked 1 tick instead of 3, and its response time drops from 7 to 5 (Demo: priority ceiling, one critical section). In scenario B, H's request for R2 at tick 2 is refused the same way; L takes R2, finishes both sections and lets H go at tick 4 (Demo: priority ceiling, no deadlock). The protocol guarantees two things:
- A job is blocked for at most the length of one critical section of one lower job: Bi = the longest critical section of a lower job on a resource whose ceiling is at least the priority of task i.
- No deadlock: once a job holds a resource with ceiling c, no other job with priority ≤ c can lock anything, so no second job can start building the other half of a cycle.
The immediate ceiling protocol
The immediate ceiling protocol (also called highest locker, or priority protect) is simpler to build: a job that locks a resource is raised at once to that resource's ceiling. In scenario A, L runs at priority 3 from tick 1, so M, released at tick 2, cannot even start until L unlocks R1 at tick 4 (Demo: immediate ceiling, block before start). A job is never blocked in the middle; all its blocking happens before it starts, and the bound is the same single critical section. POSIX offers it as PTHREAD_PRIO_PROTECT with pthread_mutexattr_setprioceiling(), and Ada calls it ceiling locking. It costs more priority changes (one at every lock, even when nobody else wants the resource), but needs no wait-for tracking.
Baker's stack resource policy
Baker's stack resource policy (SRP, 1991) moves the test from lock time to start time. Each task has a preemption level π (fixed, from its relative deadline: shorter deadline, higher level), each resource a ceiling in levels, and the system ceiling Π is the highest ceiling of the resources held right now. A job may start, and so preempt, only if it has the highest priority among the ready jobs and its π is above Π. In scenario A, M may not start at tick 2 because L holds R1 and Π = 3 (Demo: stack resource policy, one stack). With fixed priorities the schedule is the same as the immediate ceiling one. Two things are new:
- A job that has started never blocks, so it only waits for jobs that start after it and finish before it does. All jobs can then run on one shared stack, a big memory saving on small controllers. The resources panel shows the started jobs as a stack: under SRP and immediate ceiling the running job is always on top ✓; under inheritance (ticks 5, 6 and 8 in scenario A) and the original ceiling (ticks 3 and 5) a lower job runs while a higher one sits above it, so each job needs its own stack ✗.
- Preemption levels do not depend on the current priority, so SRP works the same with dynamic priorities such as earliest deadline first, where a job's priority changes at every release.
Blocking time in response-time analysis
Response-time analysis finds the worst response Ri by iteration. With shared resources it adds the blocking bound Bi, the longest time a lower job can hold task i up:
Give scenario A's tasks periods T = 8, 20 and 40 (C = 4, 5 and 5, U = 0.875). The lower critical sections are L·R1 = 3 ticks and M·R2 = 2 ticks (Demo: blocking bound in response-time analysis):
| protocol | BH | RH (T = 8) | BM | RM (T = 20) | H in the schedule |
|---|---|---|---|---|---|
| no protocol | unbounded | no bound ✗ | unbounded | no bound ✗ | blocked 5, response 9 |
| priority inheritance | 3 + 2 = 5 | 4 + 5 = 9 ✗ | 3 | 12 → 16 → 16 ✓ | blocked 3, response 7 |
| original ceiling | max(3, 2) = 3 | 4 + 3 = 7 ✓ | 3 | 16 ✓ | blocked 1, response 5 |
| immediate ceiling | 3 | 7 ✓ | 3 | 16 ✓ | blocked 0, response 4 |
| SRP | 3 | 7 ✓ | 3 | 16 ✓ | blocked 0, response 4 |
L has no lower job, so BL = 0 and RL = 14 → 18 → 22 → 27 → 31 → 31 ≤ 40 under every bounded protocol. The task set fails under inheritance only because of chained blocking: the protocol, not the CPU load, decides. M gets B = 3 under every protocol because L's section on R1 can push in front of it (by inheritance or by the ceiling). The bound is a worst case; on this one release pattern H was blocked less (3, 1 and 0 ticks).
See also the futex mutex (how a lock puts a thread to sleep and wakes it), real-time scheduling (SCHED_FIFO, priority inversion and the Mars Pathfinder) and rate-monotonic scheduling (the utilization bound and response-time analysis without blocking).
See also the cyclic executive, where slices never overlap, so shared data needs no locks at all.
What the page leaves out
One CPU, integer ticks, one job per task, and locks and priority changes that take no time. Multiprocessor protocols (MPCP, MSRP, FMLP) and spinning on another core are left out, as are nested inheritance chains longer than two, multi-unit resources (SRP handles them, the page has one unit each), and the Linux kernel's rt_mutex, which implements inheritance only. Real analyses also add jitter, context-switch and interrupt costs to the formula.