This article was reproduced from: http://blog.csdn.net/yusiguyuan/article/details/14161061
1. Priority reversal (inversion)
Because of multi-process shared resources, the process with the highest priority is blocked by a low-priority process, which causes the process with the middle priority to execute before the high-priority process, causing the system to crash. This is called priority reversal (inversion).
2. Cause
In fact, the priority reversal is blocked when the task of the high-priority (assuming a) accesses a resource that is owned by a low-precedence task (assumed to be C). And at this point there is a task with a priority higher than the resource-occupying task (c) and less than the priority of the blocked task (a) (assuming B), The task of owning a resource is suspended (the resource in possession is still in it), because the task that occupies the resource has a low priority, so it may have been suspended by another task. And the resources that it occupies have been unable to be released, so that task A has not been able to execute. The task that is lower than its priority can be executed.
Therefore, one solution is to increase the priority of the resource-occupying task, let it execute normally, and then release the resources so that task A can get the resources properly.
3. Solution (Priority inheritance/priority ceiling)
There are many ways to resolve priority reversals at this time. There are 2 kinds of methods commonly used: one is called priority inheritance, and the other is called priority ceilings.
A. Precedence inheritance (priority inheritance)
Priority inheritance is the prioritization of a low-priority task to the highest-priority task that waits for the resources it occupies. When a high-priority task is blocked by waiting for a resource, the priority of the resource's owner is automatically promoted.
B. Priority ceilings (ceilings)
The priority ceiling is the priority of the task that requests a resource to the highest priority task in all tasks that might access the resource. (This priority is called the resource's priority ceiling)
The difference between A and B:
Priority inheritance increases the priority of the resource-occupying task only when the low-priority task of the resource is blocked, and the priority ceiling, whether or not it is blocked, is promoted.
Multi-process multithreading priority understanding-priority reversal "go"