Before we even begin, let us be on the same page with some terms and conventions to be used in the rest of the explanation.
- A > B > C in terms of execution priority!
- Added means the process was added to the queue.
- Exit would mean the process terminated.
- A and C share a resource.
- In our case, C acquires the resource first and A waits for C to release it!
- A dark circle represents a shared resource being acquired.
- The Hollow circle represents wanting to acquire the resource.
- The scheduler is called every time a Process is added.
Look at what happens when A is added (@ t=7) while B is executing. In the case of a semaphore being used between A and C - there is priority inversion!
A is a higher priority than B but, B gets to execute because B is a higher priority than C, and note that C has the resource that A depends on! So, A cannot be run anyway!
Notice how B gets to run while A is waiting. This is problematic, especially in a real-time operating system. How can we prevent a higher priority process from being blocked by a lower priority process holding a required resource? One solution is to increase the priority of the process holding the resource.