CREATE OWN LIBRARY

Lock variable with Priority Inversion problem

 

See Lock variable 

 

 

*CS = Critical Section 

 

In the case of a lock variable apart from the mutual exclusion problem, has another problem is called the priority inversion problem.

Due to the priority inversion problem spin lock occurs and the system is blocked due to spin lock.

 

Example:

 

We are considering the above lock variable code and two processes like P0 and P1.

Initially Lock =0 (CS is free).

 

 

# P1 starts first and runs instructions 1,2 and 3 i.e. P1 is in the critical section and then preempted.

 

# Now P2 gets the CPU because P1 was preempted, then P2 tries to enter its critical section but stack on instruction 1 because still Lock = 1, P2  will be stacked on this loop until Lock = 0.

 

# Now CPU is busy with P2 to check the while loop continuously until Lock = 0. 

 

#And Lock = 0 is only possible when P1 will get CPU to execute instruction 4, but CPU is busy with P2 

 

P1 assign lock = 0 and leave the CS only when, P1 will get the CPU, and P2 will leave the CPU only when P2 enters into CS (when lock = 0) i.e. when P1 leaves the CS.

 

So, both processes are stopped; this concept is called spin lock.

 

It looks like a deadlock but it has a little bit of difference between deadlock and spin lock.

 

 

Conclusion:

The lock mechanism is not suitable for the priority algorithm. But in the case of the Round Robin algorithm, it has no problem.