死锁的预防: 破坏互斥条件 破坏不剥夺条件 破坏请求且保持条件 破坏循环等待条件
避免死锁的算法:
银行家算法
Available
Max
Allocation
Need
Max[i,j] = Allocation[i,j] + Need[i,j]
Allocation
Request
IF ( Request > Need )
{
IF( Request > Available )
{
Available = Available - Request
Allocation = Allocation + Request
Need = Need - Request
}
ELSE
wait()
}
ELSE
return error
安全性检查算法
Work = Available
Finish = false
find (finish==false && Need < Work)
Work = Work + Allocation
IF (Finish[ALL]==true) return Safe ELSE return Unsafe
死锁的解除
资源剥夺法
撤销进程法
进程回退法