当前位置:网站首页>死锁的条件及解决方法
死锁的条件及解决方法
2022-07-02 12:28:00 【lvhui321】
多个互相竞争资源的线程互相等待,造成永久阻塞的现象被称为死锁
死锁的条件
1.互斥性:共享资源只能被一个同一个线程占用
2.占有且等待:线程T已经获取到共享资源A,在等待共享资源B的时候未释放A
3.不可抢占:其他线程不能强行占有T占有的资源
4.循环且等待:线程 T1 等待线程 T2 占有的资源,线程 T2 等待线程 T1 占有的资源
破解死锁
可破解死锁条件除互斥性之外的三个条件 ,如下:
1.破坏“占用且等待”条件,可以一次性申请所有的资源,这样就不存在等待了。
2.破坏“不可抢占”条件,占用部分资源的线程进一步申请其他资源时,如果申请不到,可以主动释放它占有的资源,这样不可抢占这个条件就破坏掉了。
3.破坏“循环等待”条件,可以靠按序申请资源来预防。所谓按序申请,是指资源是有线性顺序
的,申请的时候可以先申请资源序号小的,再申请资源序号大的,这样线性化后自然就不存在循环
了。
边栏推荐
- 愛可可AI前沿推介(7.2)
- Two traversal sequences are known to construct binary trees
- Armv8-a programming guide MMU (4)
- /Bin/ld: cannot find -lxml2
- Lseek error
- Comment réaliser un graphique Nebula d'importation CSV hors ligne de niveau milliard
- 6095. 强密码检验器 II
- 【题解】Educational Codeforces Round 82
- Floyed "suggestions collection"
- 6090. 极大极小游戏
猜你喜欢
2020.4.12 byte written test questions B DP D monotone stack
智联招聘的基于 Nebula Graph 的推荐实践分享
【Experience Cloud】如何在VsCode中取得Experience Cloud的MetaData
[development environment] install Visual Studio Ultimate 2013 development environment (download software | install software | run software)
The outline dimension function application of small motherboard
动态规划入门二(5.647.62)
[leetcode] 1254 - count the number of closed Islands
树-二叉搜索树
又是一年毕业季
全是精华的模电专题复习资料:基本放大电路知识点
随机推荐
PyObject 转 char* (string)
可视化技术在 Nebula Graph 中的应用
2279. Maximum number of backpacks filled with stones
Xpt2046 four wire resistive touch screen
数据库系统概论第一章简答题-期末考得怎么样?
Postgressql stream replication active / standby switchover primary database no read / write downtime scenario
Comparison between rstan Bayesian regression model and standard linear regression model of R language MCMC
fastjson List转JSONArray以及JSONArray转List「建议收藏」
/Bin/ld: cannot find -lgssapi_ krb5
数据湖(十一):Iceberg表数据组织与查询
Deux séquences ergodiques connues pour construire des arbres binaires
Name of institution approved in advance
制作p12证书[通俗易懂]
[leetcode] 283 move zero
二叉树前,中,后序遍历
图数据库|Nebula Graph v3.1.0 性能报告
[leetcode] 1020 number of enclaves
The outline dimension function application of small motherboard
6095. Strong password checker II
Armv8-a programming guide MMU (4)