Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Priority Inversion
Priority inversion is an operating system scenario in which a higher priority process is preempted by a lower priority process. This implies the inversion of the priorities of the two processes, causing the system to behave opposite to its intended design.
Priority inversion typically occurs when a high-priority task waits for a resource held by a low-priority task, while a medium-priority task preempts the low-priority task, effectively blocking the high-priority task indefinitely.
How Priority Inversion Occurs
Consider three processes with different priorities:
| Process | Priority | Description |
|---|---|---|
| H | High | Critical task requiring Resource R |
| M | Medium | CPU-intensive task |
| L | Low | Currently holds Resource R |
Problems Due to Priority Inversion
Some of the problems that occur due to priority inversion are given as follows −
A system malfunction may occur if a high priority process is not provided the required resources.
Priority inversion may also lead to implementation of corrective measures. These may include the resetting of the entire system.
The performance of the system can be reduced due to priority inversion. This may happen because it is imperative for higher priority tasks to execute promptly.
System responsiveness decreases as high priority tasks may have strict time constraints or real-time response guarantees.
Sometimes there is no harm caused by priority inversion as the late execution of the high priority process is not noticed by the system.
Solutions to Priority Inversion
Some of the solutions to handle priority inversion are given as follows −
Priority Ceiling − All of the resources are assigned a priority that is equal to the highest priority of any task that may attempt to claim them. This helps in avoiding priority inversion.
Disabling Interrupts − There are only two priorities in this case i.e. interrupts disabled and preemptible. So priority inversion is impossible as there is no third option.
Priority Inheritance − This solution temporarily elevates the priority of the low priority task that is executing to the highest priority task that needs the resource. This means that medium priority tasks cannot intervene and lead to priority inversion.
No Blocking − Priority inversion can be avoided by avoiding blocking as the low priority task blocks the high priority task.
Random Boosting − The priority of the ready tasks can be randomly boosted until they exit the critical section.
Priority Inheritance Example
Priority inheritance is the most commonly used solution. When process H requests resource R held by process L, the system temporarily boosts L's priority to match H's priority, preventing M from preempting L.
| Step | Action | L's Priority | Result |
|---|---|---|---|
| 1 | L holds resource R | Low | Normal execution |
| 2 | H requests resource R | High (inherited) | L cannot be preempted by M |
| 3 | L releases resource R | Low (restored) | H gets resource and runs |
Conclusion
Priority inversion is a critical problem in real-time systems where medium-priority tasks can indefinitely block high-priority tasks. Priority inheritance is the most effective solution, temporarily boosting the priority of resource-holding tasks to prevent blocking by intermediate-priority tasks.
