Priority inversion - priority inheritance
Priority inheritance is a way to solve the problem called priority inversion.
Priority inversion
A task with low priority L becomes runnable and starts executing (1).
It acquires a mutually exclusive resource (2).
Now a task with a higher priority H becomes runnable and preempts L while L is holding the resource (3).
A third task M with priority between Hs and Ls priority (and with no need for the resource) becomes runnable, but it has to wait because H with higher priority is running (4).
H needs the resource still held by L (5), and so H stops running to wait until the resource is released.
The runnable task M prevents L from executing because of its higher priority. This leads to the priority inversion because H has to wait until M has finished (6) so that L can release the resource (7).
Priority inheritance
The priority inversion problem is solved by priority inheritance:
This means than when H needs the resource held by L, L inherits H's priority (5) in order to release the resource sooner (6). When M gets ready to run, M has to wait until the currently higher prioritized task L releases the resource and H finishes running (7).