1pthread_mutex_lock(&bus);2use_bus();3pthread_mutex_unlock(&bus);OWNERfreeINHERIToffU0.675RM MAX0.780CPULHLMMMMMMMMLHLHLLHMMMMMMMM0513 msH due 11H3M2L13
Back: the bus code, the bus lock and the utilisation meterMiddle: the three tasks and the CPU; front: the two timelinesTasks H, M, L (priority on the front) and the lock's key on its ownerAt the back: the code that uses the shared bus, the bus lock (its owner, and whether priority inheritance is on) and the utilisation meter. In the middle: the three tasks and the CPU. At the front: two 13 ms timelines and H's deadline at 11 ms. With a plain mutex, H blocks on the lock L holds, M runs 8 ms in between, and H finishes at 13 ms, 2 ms late. With priority inheritance L runs at H's priority until it unlocks, and H finishes at 5 ms. The three tasks and their times are our own example, chosen so the numbers are small. The scheduler rules (fixed priorities, preemption, a lock that blocks, priority inheritance) are the ones POSIX and Linux SCHED_FIFO follow.

Deadlines

  1. A real-time task is late if it finishes after its deadline, even when the answer is right. Each of our three periodic tasks wakes every period, needs some work time (the longest it can ever take), and must finish before its next wake-up.

Priority inversion

Priority inheritance

What happens

;; step 1/11 · deadlines
task         period   work   deadline
H control    10 ms    2 ms   end of its period
M video      20 ms    8 ms   end of its period
L logger     40 ms    3 ms   end of its period

H  steers the machine; needs the bus for 1 ms
M  encodes video; never touches the bus
L  writes a log over the bus for 3 ms

real time = predictable, not fast (Berkeley CS162)

The three tasks and their times are our own example, chosen so the numbers are small. The scheduler rules (fixed priorities, preemption, a lock that blocks, priority inheritance) are the ones POSIX and Linux SCHED_FIFO follow. The figure plays one 13 ms window, from L waking at 0 ms. In a full run each task wakes again every period; the deadline shown is the one for H's first wake-up, at 1 + 10 = 11 ms.