What is priority inversion?

前端 未结 11 2027
北恋
北恋 2020-12-22 15:05

I\'ve heard the phrase \'priority inversion\' in reference to development of operating systems.

What exactly is priority inversion?

What is the problem it\'s

11条回答
  •  Happy的楠姐
    2020-12-22 15:43

    Priority inversion is where a lower priority process gets ahold of a resource that a higher priority process needs, preventing the higher priority process from proceeding till the resource is freed.

    eg: FileA needs to be accessed by Proc1 and Proc2. Proc 1 has a higher priority than Proc2, but Proc2 manages to open FileA first.

    Normally Proc1 would run maybe 10 times as often as Proc2, but won't be able to do anything because Proc2 is holding the file.

    So what ends up happening is that Proc1 blocks until Proc2 finishes with FileA, essentially their priorities are 'inverted' while Proc2 holds FileA's handle.

    As far as 'Solving a problem' goes, priority inversion is a problem in itself if it keeps happening. The worst case (most operating systems won't let this happen though) is if Proc2 wasn't allowed to run until Proc1 had. This would cause the system to lock as Proc1 would keep getting assigned CPU time, and Proc2 will never get CPU time, so the file will never be released.

提交回复
热议问题