Priority inversion (how not to use semaphores)
Semaphores can be used to synchronize multiple tasks. But, a limitation of semaphores is that they have no concept of task priority. This can be a problem when a higher-priority task waits on a semaphore that is being held by a lower-priority task. The higher-priority task can be inadvertently delayed by the relatively slow progress of the lower-priority task. This problem is called priority inversion.
This section explains priority inversion, and demonstrates it in an example-program. A solution to the problem is an enhanced form of semaphores called mutexes, and they are presented in a later section.
Understanding priority inversion
Let’s look at a common problem that occurs when attempting to use a binary semaphore to provide mutual-exclusion functionality.
Consider three tasks, A, B, and C, where A has the highest priority, B has the middle priority, and C has the lowest priority. Tasks A and C rely on a semaphore...