This problem is a case of synchronization.
Suppose, we have 2 processes p1 and p2 both accessing a shared resource, so if any process p1 or p2 is in it’s critical section other process will be in busy waiting or sleeping state (depending upon the synchronization mechanism).
On it’s own this is not a problem, but when we factor in process allocation, particularly Priority Based Preemptive Process Allocation then we’ll be seeing much bigger problems.
For our discussion, we’ll say p1 has higher priority than p2 and p2 is currently running and is in its critical section.
- When p1 becomes ready the scheduler preempts p2 which is in it’s critical section and gives cpu to p1. After a while when p1 tries to access it’s critical section, p1 sleeps and p2 resumes. Now suppose, a process p3 such that priority of p1>p3>p2 and p3 becomes ready then p3 will preempt p2 and execute first. So, a lower priority process (p3) affects how long a high priority process (p1) waits.
- When p1 becomes ready the scheduler preempts p2 which is in it’s critical section and gives cpu to p1. After a while p1 tries to access it’s critical section, rather than p1 sleeping if it keeps busy waiting then p1 is waiting for p2 to get out of it’s critical section and p2 is waiting for p1 to finish or sleep to get cpu which is a deadlock.
This problem is solved using Priority-Inheritance Protocol. – According to this protocol, all processes that are accessing resources needed by a higher-priority process inherit the higher priority until they are finished with the resources in question. When the are finished, their priorities revert back to their original values.
Source – Galvin Book and others.