No preemption: a resource can be released only voluntarily by the process holding it, after that process has completed its task.
非抢占式的
Circular wait: there exists a set {P0,P1,…,Pn} of waiting processes such that P0 is waiting for a resource that is held by P1, P1 is waiting for a resource that is held by P2,…,Pn–1 is waiting for a resource that is held by Pn, and Pn is waiting for a resource that is held by P0.
Mutual Exclusion – not required for sharable resources; must hold for nonsharable resources.
互斥条件必须成立,因为总是有资源是非共享的。
Hold and Wait – must guarantee that whenever a process requests a resource, it does not hold any other resources.
应确保当每一个进程申请一个资源的时候,它不能抢占其他资源
Require process to request and be allocated all its resources before it begins execution, or allow process to request resources only when the process has none (release all current resources before requesting any additional ones).
Low resource utilization; starvation possible. (example: copy data from DVD drive to a disk file, sorts the file, then prints the results to a printer.)
两个缺点:
资源利用率较低
可能发生饥饿
No Preemption –
If a process that is holding some resources requests another resource that cannot be immediately allocated to it, then all resources currently being held are released.
Preempted resources are added to the list of resources for which the process is waiting.
Process will be restarted only when it can regain its old resources, as well as the new ones that it is requesting.
可能会导致重复的 request,导致系统效率低下
Circular Wait – impose a total ordering of all resource types, and require that each process requests resources in an increasing order of enumeration. (page 255)
When a process requests an available resource, system must decide if immediate allocation leaves the system in a safe state.
System is in safe state if there exists a sequence <P1,P2,…,Pn> of ALL the processes such that for each Pi, the resources that Pi can still request can be satisfied by currently available resources + resources held by all the Pj, with j < i.
That is:
If Pi resource needs are not immediately available, then Pi can wait until all Pj have finished.
When Pj is finished, Pi can obtain needed resources, execute, return allocated resources, and terminate.
When Pi terminates, Pi+1 can obtain its needed resources, and so on.
image-20251218115506265
安全状态下,操作系统就能避免死锁
但在非安全状态下,操作系统可能会导致死锁
实际上,unsafe 意味着在系统进行某些进程操作后,会引发死锁
image-20251218115552141
这里需要注意的是,An unsafe state implies that some unfortunate sequence of events mightlead to a deadlock。反过来说,unsafe 的状态有时候并不会导致死锁的发生。若是一个进程在执行的过程中发现自己其实并不需要自己声明的那么多的资源(比如,只要一半),从而解决死锁。
If detection algorithm is invoked arbitrarily, there may be many cycles in the resource graph and so we would not be able to tell which of the many deadlocked processes “caused” the deadlock.