DEADLOCK Dsatm
DEADLOCK Dsatm
DEADLOCK Dsatm
request
use
release
Deadlock Characterization
Necessary Condition
Deadlock can arise if four conditions hold simultaneously.
Mutual exclusion: only one process at a time can use a resource
Hold and wait: a process holding at least one resource is waiting
to acquire additional resources held by other processes
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.
Resource-Allocation Graph
Process
Pi requests instance of Rj
Pi is holding an instance of Rj
Resource Allocation Graph With A Deadlock
Deadlock Avoidance
Safe State
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 in the systems 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
If a system is in safe state no deadlocks
If a system is in unsafe state possibility of deadlock
Avoidance ensure that a system will never enter an unsafe
state
Avoidance Algorithms
o Single instance of a resource type
Use a resource-allocation graph
o Multiple instances of a resource type
Use the banker’s algorithm
Banker’s Algorithm
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
Data Structures for the Banker’s Algorithm
Let n = number of processes, m = number of resources types.