Priority Inversion

With a semaphore:
  • Thread A waited for a unit from the semaphore and got it.
  • Thread B wakes up and pre-empts thread A.
  • Thread C wakes up and pre-empts thread B.
  • Thread C then waits for a unit from the semaphore; thread A has the unit, so thread C goes to sleep, and thread B continues to run.
  • Thread C has a higher priority than thread A and B but is “blocked” because thread A has the required resource (unit from the semaphore) and thread B has the CPU.
 
Additional problem:
6. After returning successfully from WaitForRtSemaphore, the thread may be deleted. Now the application is stuck because a unit will not be sent back to the semaphore.
Proper cleanup to return any semaphore when deleting a thread is important.