当前位置:网站首页>死锁的条件及解决方法
死锁的条件及解决方法
2022-07-02 12:28:00 【lvhui321】
多个互相竞争资源的线程互相等待,造成永久阻塞的现象被称为死锁
死锁的条件
1.互斥性:共享资源只能被一个同一个线程占用
2.占有且等待:线程T已经获取到共享资源A,在等待共享资源B的时候未释放A
3.不可抢占:其他线程不能强行占有T占有的资源
4.循环且等待:线程 T1 等待线程 T2 占有的资源,线程 T2 等待线程 T1 占有的资源
破解死锁
可破解死锁条件除互斥性之外的三个条件 ,如下:
1.破坏“占用且等待”条件,可以一次性申请所有的资源,这样就不存在等待了。
2.破坏“不可抢占”条件,占用部分资源的线程进一步申请其他资源时,如果申请不到,可以主动释放它占有的资源,这样不可抢占这个条件就破坏掉了。
3.破坏“循环等待”条件,可以靠按序申请资源来预防。所谓按序申请,是指资源是有线性顺序
的,申请的时候可以先申请资源序号小的,再申请资源序号大的,这样线性化后自然就不存在循环
了。
边栏推荐
- PyObject 转 char* (string)
- 6090. 极大极小游戏
- Make p12 certificate [easy to understand]
- Jsp+mysql006 community management system
- 如何實現十億級離線 CSV 導入 Nebula Graph
- 6092. 替换数组中的元素
- Two traversal sequences are known to construct binary trees
- 动态规划入门一,队列的bfs(70.121.279.200)
- [leetcode] 695 - maximum area of the island
- The sea of stars hidden behind the nebula graph
猜你喜欢

Why does the system convert the temp environment variable to a short file name?

全是精华的模电专题复习资料:基本放大电路知识点

Ant group's large-scale map computing system tugraph passed the national evaluation

XPT2046 四线电阻式触摸屏

Aike AI frontier promotion (7.2)

Introduction to dynamic planning I, BFS of queue (70.121.279.200)

动态规划入门二(5.647.62)

PostgresSQL 流复制 主备切换 主库无读写宕机场景

Thoroughly understand browser strong cache and negotiation cache

已知两种遍历序列构造二叉树
随机推荐
睿智的目标检测23——Pytorch搭建SSD目标检测平台
6091. Divide the array so that the maximum difference is K
Lseek error
Nebula Graph & 数仓血缘关系数据的存储与读写
[salesforce] how to confirm your salesforce version?
制作p12证书[通俗易懂]
List of sergeant schools
beforeEach
Wavedec2 in MATLAB, talk about the wavedec2 function [easy to understand]
Digital collection system development (program development) - Digital Collection 3D modeling economic model system development source code
Ant group's large-scale map computing system tugraph passed the national evaluation
将点云坐标转换成世界坐标的demo
Xpt2046 four wire resistive touch screen
Wise target detection 23 - pytoch builds SSD target detection platform
/Bin/ld: cannot find -lpam
2278. Percentage of letters in string
Make p12 certificate [easy to understand]
基于 Nebula Graph 构建百亿关系知识图谱实践
解决BASE64Encoder报错的问题
6090. Minimax games