优先级反转
我在理解
文章中的优先级反转片段时遇到问题:
考虑有一个任务 L,具有低 优先事项。该任务需要资源 R. 考虑 L 正在运行并且它 获取资源R。现在,有 另一个任务 H,具有高优先级。 该任务还需要资源 R。 考虑H在L获得后开始 资源 R。现在 H 必须等到 L 放弃资源 R。
一切都按预期进行 这点,但是当 新任务 M 以中等优先级开始 这段时间。 ` 因为 R 仍然是 在使用中(由 L),H 无法运行。自从M 是最高优先级的解锁 任务,它将被安排在L之前。 由于L已被M抢占,L 不能放弃R。所以M会跑 直到完成,然后 L 将运行 - 至少到了可以的程度 放弃 R - 然后 H 将运行。 因此,在上述场景中,任务 中等优先级在任务之前运行 高度优先,有效地为我们提供了 优先级反转。
该问题与本文的第二部分相关。为什么具有 H(较高)优先级的进程无法抢占具有 L(较低)优先级的进程,但具有 M(中)优先级的进程可以抢占?即,如果由于 R 正在使用而 H 被阻止,为什么 M 也没有被阻止?
I am having problem understanding Priority Inversion
Snippet from the article:
Consider there is a task L, with low
priority. This task requires resource
R. Consider that L is running and it
acquires resource R. Now, there is
another task H, with high priority.
This task also requires resource R.
Consider H starts after L has acquired
resource R. Now H has to wait until L
relinquishes resource R.Everything works as expected up to
this point, but problems arise when a
new task M starts with medium priority
during this time. ` Since R is still
in use (by L), H cannot run. Since M
is the highest priority unblocked
task, it will be scheduled before L.
Since L has been preempted by M, L
cannot relinquish R. So M will run
till it is finished, then L will run -
at least up to a point where it can
relinquish R - and then H will run.
Thus, in above scenario, a task with
medium priority ran before a task with
high priority, effectively giving us a
priority inversion.
The question is relevant to the second part of the article. Why is that a process with H (Higher) priority cannot pre-empt a process with L (lower) priority but a process with M (medium) priority can pre-empt? i.e. If H was put to block since R was in use, why was M not blocked as well ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为M不需要资源R,所以它可以在L仍在使用时运行;另一方面,在 L 能够释放 R 之前,H 无法运行。
Because M does not require resource R, so it is able to run while L still has it in use; H, on the other hand, cannot run until L is able to release R.