当前位置:网站首页>Priority inversion and deadlock
Priority inversion and deadlock
2022-07-06 11:58:00 【Weiyuan escort agency】
1、 priority reverse
When resources are locked, low priority tasks preempt high priority tasks .
give an example : Mission A、B、C, The priority from low to high is 1、2、3, All tasks are completely preemptive , Mission A and C Shared resources R.
1. Mission A function , And for resources R Lock ;
2. Mission C Be activated to preempt tasks A, And try to resource R Lock , therefore C Get into WAITING state ,A Recover from the occupied place ;
3. Mission B Be activated and preempt the task A, Mission B Successful execution ;
4. Mission A Resume execution and release resources R, Mission A Execution completed ;
5. Mission C Recover and restore resources R Lock and complete the execution .
We observe the task B Priority is lower than task C But actually occupied the task C, This is priority reversal . In systems with high real-time requirements, it is unacceptable for such high priority tasks to be unexpectedly delayed . More serious is due to priority reversal , Mission C The delay time of is uncertain , Because anything better than the task A Tasks with high priority can preempt tasks A.
2、 Deadlock
Locking resources causes a conflict between two tasks , Each task locks the resources needed by another task , Make every task impossible .
give an example : Mission A、B, Share two resources R1、R2, Other situations are the same as those in priority inversion .
1. Mission A Yes R1 Lock ;
2. Mission B preemption A, Also on R2 Lock , Then try to R1 Lock , because R1 It's locked , So the task B Get into WAITING state ;
3. Mission A Resume execution , Try to be on R2 Lock , because R2 It's locked , So the task A Get into WAITING state ;
4. Other tasks enter the execution state , And the task A and B Can never continue .
Deadlock is likely not to be found in normal tests , After delivery to the customer, it is more difficult to be checked because the problem is difficult to recur .
There are many ways to solve priority inversion and deadlock , stay OSEK In the use of OS Priority ceiling protocol (priority ceiling protocol) It's the most effective way .
RT-thread Mutually exclusive Priority inheritance mechanism in quantity
2018-11-01 13:23:58
The three threads are H Threads 、M Threads 、L Threads
1. The priority order of the three threads is :H Threads > M Threads > L Threads ;
2. During normal operation H Threads can break M Threads and L Threads , M Threads can break L Threads ;
3. Suppose a resource in the system is protected , At this time, the resource is L Threads are using , At some point H The thread needs to use this resource , but L The thread is not used up ,H The thread cannot apply and enters the blocking state , At this time, priority reversal has occurred ;
When there is no priority inheritance mechanism :
If L When a thread is executing ,M The thread just woke up , because M Threads have a high priority , Will interrupt L Threads , preemption CPU Right to use , until M Thread execution complete ;
M Thread will CPU The right to use L Threads ,L The thread continues to execute ,L Release the resource after execution ;
H The thread gets the resource , Remove from the blocking state ;
This process , High priority H Waiting for the M Threads +L Thread time , If there are more threads , Then the system crashed , I can't afford to wait !
When there is a priority inheritance mechanism :
stay H When Xianchen applied for resources, he entered the blocking state because he could not apply for resources , The system will put the currently used resources L The priority of the thread is temporarily increased to H Threads have the same priority ;
here M The thread will not be interrupted when it is awakened L Threads ;
L Thread execution completed , Release resources ,H The thread obtains resources and continues to execute ,H The waiting time of the thread is only L Thread execution time .
original text :
OSEK study notes – Priority inversion and deadlock
边栏推荐
猜你喜欢
随机推荐
Common regular expression collation
荣耀Magic 3Pro 充电架构分析
2020 WANGDING cup_ Rosefinch formation_ Web_ nmap
【flink】flink学习
C语言函数之可变参数原理:va_start、va_arg及va_end
Gallery's image browsing and component learning
express框架详解
[CDH] modify the default port 7180 of cloudera manager in cdh/cdp environment
Oppo vooc fast charging circuit and protocol
小L的试卷
Basic use of pytest
OPPO VOOC快充电路和协议
Funny cartoon: Programmer's logic
几个关于指针的声明【C语言】
C语言,log打印文件名、函数名、行号、日期时间
TypeScript
数据库面试常问的一些概念
PyTorch四种常用优化器测试
L2-004 is this a binary search tree? (25 points)
[MRCTF2020]套娃