简体   繁体   中英

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 (eg 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?

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.

Pre-empting (so that the task gets CPU time) is not enough, if the lower-priority task also holds some exclusive resource. Then the higher-priority task will just try to acquire the resource (by locking a mutex, for instance) which will block it until the lower-priority task is done with the resource.

Thus, the higher-prio task ends up blocked (not running) while the lower-prio task gets to run.

Priority inversion is a form of indefinite postponement of preemptive executives with shared resources.

Priority inversion occurs when a high priority tasks requests access to shared resource which is currently allocated to low priority task. The high priority task must be blocked until the low priority task releases the resource.

This problem becomes complex when the low priority task is prevented from executing by one or more medium priority tasks. Because the low priority task is not executing, it cannot complete its interaction with the resource and release that resource. Hence, the high priority task is effectively prevented from executing by lower priority tasks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM