Deadlock
简化自这篇博客
定义:
a deadlock is a state in which each member of a group of actions, is waiting for some other member to release a lock.
发生条件:
Mutual Exclusion – There should be at least one non-shareable resource.//有不可共享资源
Hold and Wait – A deadlock will occur if a process can hold a resource and then wait for another. If only every resource can wait for a resource (without holding), there won’t be any deadlock as no one is holding on to any resource.// 进程所获得的资源在未使用完毕之前,资源申请者不能强行地从资源占有者手中夺取资源,而只能由该资源的占有者进程自行释放
No preemption – //占有又申请
Circular Wait – If each process holds a resource and wait for another resource, which is held by another waiting process, and if it finally forms a circular wait sequence, a deadlock will occur.
预防方法:
- 当一个进程已占有了某些资源,它又申请新的资源,但不能立即被满足时,它必须释放所占有的全部资源,以后再重新申请。它所释放的资源可以分配给其它进程。
- 可以实行资源预先分配策略。即进程在运行前一次性地向系统申请它所需要的全部资源。如果某个进程所需的全部资源得不到满足,则不分配任何资源,此进程暂不运行。
- 打破循环等待条件,实行资源有序分配策略。采用这种策略,即把资源事先分类编号,按号分配,使进程在申请,占用资源时不会形成环路。所有进程对资源的请求必须严格按资源序号递增的顺序提出。
- 安全序列,银行家算法Banker's Algorithm 各种矩阵