RobotGuide
Labs/RTOS Scheduling and Priority Inversion

Lab 7 / 15 · Timing · A/B

RTOS Scheduling and Priority Inversion

Three tasks fight over one CPU; flip on priority inheritance and see whether the high-priority task still gets stuck.

Math: High school math is enoughNo coding neededNo hardware needed≈ 9 min

Scheduling policy

Medium-priority task runtime1.2 ms

The medium-priority task never touches the lock; it is just 'busy'. The busier it is the less chance the low-priority task gets to release the lock when inheritance is off.

Readouts

High priority blocked—
Medium priority jumps ahead—
Low priority releases lock—

A simplified model: single core, fixed priorities, time slicing only among equal priorities. The magnitudes reference a real FreeRTOS but do not replace measurement.

What problem this lab solves

Interviews ask «how do you fix priority inversion». Most people can recite the words «priority inheritance» but have never seen what it actually changes. This experiment puts three tasks on one timeline: who runs, who waits on the lock, and how long the high-priority task is stuck — visible at a glance.

How to read the figure

Three rows are three tasks, the horizontal axis is time, and only one row runs at any instant. Red is the high-priority task: the moment it becomes ready it should preempt everything. If it starts late, look at the row above it — a low-priority task is holding the lock. Flip the switch to «inheritance on»: the low-priority task temporarily rises to its level and the middle priority can no longer cut in. The hatched region is exactly how long the high-priority task was stuck.

Hands-on

First turn inheritance off and read the «high priority stuck» milliseconds; turn it on and see how far it drops. Then stretch the middle task's execution time and watch the stuck time grow with it when inheritance is off — that is what «unbounded» really means.

Related topics

Next labs (in play-learn order)