If graph contains a cycle ± if only one instance per resource type, then deadlock ± if several instances per resource type, possibility of deadlock.
Methods for handling deadlocks ° Ensure that the system will never enter a deadlock state. ° Allow the system to potentially enter a deadlock state, detect it and then recover ° Ignore the problem and pretend that deadlocks never occur in the system; ± Used by many operating systems, e.g. UNIX
Deadlock Management ± Prevention ± Design the system in such a way that deadlocks can never occur ± Avoidance ± Impose less stringent conditions than for prevention, allowing the possibility of deadlock but sidestepping it as it occurs. ± Detection ± Allow possibility of deadlock, determine if deadlock has occurred and which processes and resources are involved. ± Recovery ± After detection, clear the problem, allow processes to complete and resources to be reused. May involve destroying and restarting processes.
Deadlock Prevention ± If any one of the conditions for deadlock (with reusable resources) is denied, deadlock is impossible. ± Restrain ways in which requests can be made ° Mutual Exclusion ± non-issue for sharable resources ± cannot deny this for non-sharable resources (important) ° Hold and Wait - guarantee that when a process requests a resource, it does not hold other resources. ± Force each process to acquire all the required resources at once. Process cannot proceed until all resources have been acquired. ± Low resource utilization, starvation possible
Deadlock Prevention (cont.) ° No Preemption ± If a process that is holding some resources requests another resource that cannot be immediately allocated to it, the process releases the resources currently being held. ± 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. ° Circular Wait ± Impose a total ordering of all resource types. ± Require that processes request resources in increasing order of enumeration; if a resource of type N is held, process can only request resources of types > N.
Deadlock Avoidance ° Set of resources, set of customers, banker ° Rules ± Each customer tells banker maximum number of resources it needs. ± Customer borrows resources from banker. ± Customer returns resources to banker. ± Customer eventually pays back loan. ° Banker only lends resources if the system will be in a safe state after the loan.
Deadlock Avoidance ° Requires that the system has some additional apriori information available. ± Simplest and most useful model requires that each process declare the maximum number of resources of each type that it may need. ± The deadlock-avoidance algorithm dynamically examines the resource-allocation state to ensure that there can never be a circular-wait condition. ± Resource allocation state is defined by the number of available and allocated resources, and the maximum demands of the processes.
Safe state ° When a process requests an available resource, system must decide if immediate allocation leaves the system in a safe state.
- One '20