Methods For Handling Deadlocks
Methods For Handling Deadlocks
Deadlock Prevention
Mutual Exclusion – not required for sharable resources; must hold for
non-sharable 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 sources before it
begins execution, or allow process to request resources only when the
process has none.Low resource utilization; starvation possible. Restrain
the ways request can be made.
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.
Circular Wait – impose a total ordering of all resource types, and
require that each process requests resources in an increasing order of
enumeration
Deadlock Avoidance
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.
Requires that the system has some additional a
priori information available.
Safe State
Basic Facts
Multiple instances.
Each process must a priori claim maximum use.
When a process requests a resource it may have to wait.
When a process gets all its resources it must return them in a finite amount
of time.
Safety Algorithm
Deadlock Detection
Allow system to enter deadlock state
Detection algorithm
Recovery scheme
Detection Algorithm
1. Let Work and Finish be vectors of length m and n, respectively
Initialize:
(a) Work = Available
(b) For i = 1,2, …, n, if Allocation i ≠ 0, then
Finish [i] = false; otherwise, Finish [i] = true.
2. Find an index i such that both:
(a) Finish [i] == false
(b) Request i ≤ Work
If no such i exists, go to step 4.
3. Work = Work + Allocation i
Finish [i] = true
go to step 2.
4. If Finish [i] == false, for some i, 1 ≤ i ≤ n, then the system is in deadlock
state.
Moreover, if Finish [i] == false, then Pi is deadlocked.
Algorithm requires an order of O (m x n2) operations to detect whether the
system is in deadlocked state.