written 5.8 years ago by |
(i) Priority Inversion is a condition in which low priority task executes while a high priority task waits(blocked) due to resource contentions.
(ii) PI happens because in poorly designed RTFS.
Consider following example:
(iii) Let A, B, C $\to$ 3 process/task.
A- high priority, B- med priority, C- lower priority
Process/task A and task C shares a variable 'X' and access to this variable is sync with use of semaphore.
(iv) Now task C is ready and is picked up for execution by scheduler and acquires the shared variable.
(v) But now Task A is blocked due to unavailability of resource and waiting for the resource being used by task B which has itself pre-empted the task C.
(vi) In this situation, the task A which has high priority level has been effectively inverted to the lower priority level.
This is known as PI.
Bounded inversion: If the inversion will get over in a fixed time boundary, then it is called as bounded priority inversion.
Unbounded inversion: The time for which priorities will be inverted is not bounded then is called as unbounded priority inversion.
Solutions to Priority Inversion
(i) Priority Ceiling
In this case, the lower priority task has the resource due to which the higher task enters into blocked state, is temporarily given highest(top most) priority of all task.
This ensures that no lower or other task will be able to acquire the resource in between, since it has become the highest priority task.
This will ensure No PI take place.
(ii) Priority inheritance
- In this case task having lower priority and accessing shares variable/data is given priority; just above the higher priority(operation remains same as above)