Wednesday, January 1, 2014

Difference between priority inversion and priority inheritance

Consider two processes A and B which use a common lock. Process A has a much higher priority than process B. In this case if process B holds the common lock, then process A will not have a chance to run until process B releases the lock. In the mean time, if the scheduler runs it could always pick a process C which has priority in between A and B to run.

Hence, now process C which has priority less than A runs before A thereby making the priorities assigned to the processes useless. Also, since C has a higher priority than B it runs longer further preventing B from releasing the common lock for A. In the worst case we can imagine a lot of other processes like B which have priorities between A and B.

Why Pre-emption does not work here:
In this case even if we enable kernel pre-emption, all it can ensure is making the process B relinquish control. However, process A still can't run until the common lock is released by B.

Solutions:

1. Careful and minimal use of locks: Works best in most cases.

2. Priority inheritance: In this mechanism the process holding the lock inherits the priority of the highest priority process holding the lock. In our example, this will ensure that B has the same priority as A and runs often enough to release the resource soon enough for A to use it. This has been an often contended approach to handling priority inversion and is not the best way out of the situation.

0 comments:

Post a Comment