Os 08
Os 08
System Model
Deadlock Characterization
Methods for Handling Deadlocks
Deadlock Prevention
Deadlock Avoidance
Deadlock Detection
Recovery from Deadlock
Example
System has 2 tape drives.
Two Processes (P1 and P2),
each hold one tape drive and each needs another one.
CPU cycles
Memory space
I/O devices
Mutual exclusion
Hold and wait
No preemption
Circular wait
Mutual exclusion
Only one process at a time
can use a resource.
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
Request edge
Directed edge Pi Rj
Assignment edge
Directed edge Rj Pi
Prof. D.S.R. Murthy OS-8 Deadlocks 7
Example of Resource Allocation Graph
Mutual Exclusion
Not required for sharable resources.
Must hold for non–sharable resources.
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
Imposes a total ordering of all resource types,
and require that each process requests resources
in an increasing order of enumeration.
Deadlock–avoidance algorithm
Dynamically examines the resource-allocation state
to ensure that there can never be a circular-wait
condition.
Resource–allocation state
Defined
Prof. by the no. of available
D.S.R. Murthy and allocated resources, 17
OS-8 Deadlocks
Safe State
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.
Prof. D.S.R. Murthy OS-8 Deadlocks 19
Safe, Unsafe, Deadlock State
If (Need ≤ Available)
Available = Available + Allocated
Sequence is P1, P3, P4, P0, P2 and the System is in Safe State.
Detection algorithm.
Recovery scheme.
Rollback
Return to some safe state.
Restart process for that state.
Starvation
Same process may always be picked as victim,
include no. of rollback in cost factor.