What is priority inversion and how is it prevented?
Answer
Priority inversion occurs when a high-priority task is blocked waiting for a resource held by a low-priority task, while a medium-priority task runs. Example: Task L (low) holds mutex, Task H (high) waits for mutex, Task M (medium) runs and preempts L, preventing L from releasing the mutex. H is effectively blocked by M. Mars Pathfinder experienced this issue. Solutions: Priority Inheritance - temporarily raise the priority of the task holding the resource to that of the highest waiting task; most common approach. Priority Ceiling - set mutex priority to highest task that will use it; all tasks using the mutex run at ceiling priority. Avoiding shared resources or minimizing critical section time also helps.
Master These Concepts with IIT Certification
175+ hours of industry projects. Get placed at Bosch, Tata Motors, L&T and 500+ companies.