Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Last Updated: Mar 27, 2024

Difference between Priority Inversion and Priority Inheritance

Leveraging ChatGPT - GenAI as a Microsoft Data Expert
Speaker
Prerita Agarwal
Data Specialist @
23 Jul, 2024 @ 01:30 PM
Operating Systems

Introduction

Both Priority Inversion and Priority Inheritance are operating systems concepts and come under preemptive priority scheduling. Preemptive Priority Based Scheduling is a CPU scheduling algorithm where a higher priority process can interrupt a lower priority process and complete its execution before the lower priority process, which may have started executing first. To learn more about other scheduling algorithms, visit CPU Scheduling

Also Read About, FCFS Scheduling Algorithm, Multiprogramming vs Multitasking

Priority Inversion 

It is a problem that arises when working in a preemptive priority scheduling system. It occurs when a higher priority process has to wait for a comparatively lower priority process to complete. Suppose there are three processes one with low priority L, one with high priority H, and one with medium priority M. Now, suppose L is running and has entered CS. Now H arrives, but it has to wait for L to come out of its CS. Now M arrives, preempts L, and completes its execution. When M is running, H cannot preempt M because it waits for L to exit the CS. Note that L and H access shared variables, and M has no variable in common with L and H. Here H is waiting for M; this is the Priority Inversion problem.

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

Priority Inheritance

Priority Inheritance is the solution to priority inversion. In the above example, with the help of priority inheritance, when L is executing, it will inherit the priority of H as H is waiting for it to come out of CS. Now M would not be able to preempt L, and the system works fine again. So L has inherited the highest priority of the process, waiting for it to come out of CS.

Difference between Priority Inversion and Priority Inheritance

In simple words, we can say that priority inversion is the problem that arises when we are working with a preemptive priority scheduling algorithm. Priority Inheritance is the solution to the problem of priority inversion. More differences can be seen in the below table.

Priority Inversion 

Priority Inheritance

Priority Inversion is a problem where a lower priority process is executed before a higher priority process. Priority Inheritance is the solution to the priority inversion problem
In this, the priorities of the processes are inverted due to the execution of the critical section. This is the method of assigning the maximum priority to the process among the processes waiting for it to exit CS.
We may use various strategies to address the issue of priority inversion, including Priority Inheritance, Priority ceiling, etc. It is one of the best techniques to solve the problem of priority inversion.
It may cause undesired order of execution of processes.  When there are layered locks, priority inheritance might lead to lower worst-case performance.

In this article, we have discussed the difference between priority inversion and priority inheritance.

Must Read Evolution of Operating System and Open Source Operating System

Frequently Asked Questions

What is the difference between preemptive and non-preemptive priority scheduling?

In preemptive priority scheduling, when a higher priority process comes in the ready queue, it can preempt the lower priority process and complete its execution. But in non-preemptive, processes can not be preempted or interrupted once they start executing.

What is the solution to Priority Inversion?

The solution to Priority Inversion is Priority Inheritance. In priority inheritance, we assign the priority of the process with the highest priority among the processes that the waiting for the lower priority process to come out of the critical section.

Which scheduler is responsible for selecting the next process to be executed by the CPU?

The short-term scheduler selects the process that needs to be assigned to the CPU next. It is the job of the dispatcher to load the processes in the main memory to be executed.

What is a critical section?

A critical section is that part of the process that accesses the shared variables. No two processes can be in the critical section at the same time when we have a commonly shared variable. 

What is priority scheduling?

In priority scheduling, each process is assigned a priority, and the order of execution of the process depends upon the priority assigned. Higher priority processes are executed first.

Conclusion

In this article, We have discussed Priority Inversion and Priority Inheritance. We also discussed the key difference between priority inversion and priority inheritance. To learn the operating system in detail, visit Operating System Track. I hope you would have gained a better understanding of these topics now!

Recommended Readings:


Do check out The Interview guide for Product Based Companies as well as some of the Popular Interview Problems from Top companies like Amazon, Adobe, Google, Uber, Microsoft, etc. on Coding Ninjas Studio.

Also check out some of the Guided Paths on topics such as Data Structure and Algorithms, Competitive Programming, Operating Systems, Computer Networks, DBMS, System Design, etc. as well as some Contests, Test Series, Interview Bundles, and some Interview Experiences curated by top Industry Experts only on Coding Ninjas Studio.

Happy Coding!

Topics covered
1.
Introduction
2.
Priority Inversion 
3.
Priority Inheritance
4.
Difference between Priority Inversion and Priority Inheritance
5.
Frequently Asked Questions
5.1.
What is the difference between preemptive and non-preemptive priority scheduling?
5.2.
What is the solution to Priority Inversion?
5.3.
Which scheduler is responsible for selecting the next process to be executed by the CPU?
5.4.
What is a critical section?
5.5.
What is priority scheduling?
6.
Conclusion