Search code examples
coperating-systemembeddedscheduled-tasksrtos

I cannot understand how priority inversion can occur


HPT -> Highest Priority Task.
MPT -> Medium Priority Task
LPT -> Low Priority Task

Hello Friend, I read priority inversion from many websites (e.g http://www.embeddedheaven.com/priority-inversion-2.htm). But I would like to know, why HPT can not preempt LPT? If you will read the section 3.3 Unbounded Inversion, It says if LPT has acquired the resource, same time if HPT is ready but blocked because of LPT. But if MPT is ready then it preempts the LPT and executes itself. Then LPT has to wait till MPT finishes. Once MPT finishes then LPT resumes. And once LPT finishes then HPT starts. So my question is why can't HPT preempt LPT or MPT?


Solution

  • The wikipedia explanation is perhaps a bit easier to understand than the link you provided: https://en.wikipedia.org/wiki/Priority_inversion

    To answer your question in slightly different words, what happens roughly chronologically is

    1. LPT acquires R
    2. MPT becomes runnable, thus preempting LPT
    3. HPT becomes runnable, thus preempting MPT
    4. HPT tries to acquire R and blocks
    5. Scheduler chooses the highest priority task which is runnable, that is MPT.
    6. MPT runs unbounded (potentially "forever"), thus preventing LPT from running and releasing R, and thus prevents HPT from running.