当前位置:网站首页>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
边栏推荐
- Dependency in dependencymanagement cannot be downloaded and red is reported
- 互联网协议详解
- Matlab learning and actual combat notes
- 机器学习--决策树(sklearn)
- Selective sorting and bubble sorting [C language]
- Hutool中那些常用的工具类和方法
- RT-Thread的main线程“卡死”的一种可能原因及解决方案
- 分布式事务的实现方案
- {one week summary} take you into the ocean of JS knowledge
- 分布式节点免密登录
猜你喜欢
Reno7 60W super flash charging architecture
[yarn] CDP cluster yarn configuration capacity scheduler batch allocation
Connexion sans mot de passe du noeud distribué
[yarn] yarn container log cleaning
R & D thinking 01 ----- classic of embedded intelligent product development process
Analysis of charging architecture of glory magic 3pro
Small L's test paper
Detailed explanation of 5g working principle (explanation & illustration)
Principle and implementation of MySQL master-slave replication
機器學習--線性回歸(sklearn)
随机推荐
4、安装部署Spark(Spark on Yarn模式)
电商数据分析--薪资预测(线性回归)
ESP8266通过Arduino IDE连接Onenet云平台(MQTT)
数据分析之缺失值填充(重点讲解多重插值法Miceforest)
[mrctf2020] dolls
Composition des mots (sous - total)
[Flink] Flink learning
R & D thinking 01 ----- classic of embedded intelligent product development process
小L的试卷
Come and walk into the JVM
Some concepts often asked in database interview
FTP文件上传文件实现,定时扫描文件夹上传指定格式文件文件到服务器,C语言实现FTP文件上传详解及代码案例实现
Reno7 60W super flash charging architecture
Redis interview questions
wangeditor富文本组件-复制可用
Gallery's image browsing and component learning
Reading notes of difficult career creation
arduino UNO R3的寄存器写法(1)-----引脚电平状态变化
Togglebutton realizes the effect of switching lights
mysql实现读写分离