Deadlock
Deadlock
DEFINITION OF DEADLOCK
A set of two or more processes are deadlocked if
they are blocked (i.e., in the waiting state) each
holding a resource and waiting to acquire a
resource held by another process in the set.
Or
A process is deadlocked if it is waiting for an
event which is never going to happen.
Deadlocks can occur via system calls, locking, etc.
2
EXAMPLE OF DEADLOCK
P_0 P_1
---------- ----------
A.wait(); B.wait();
B.wait(); A.wait();
A.signal(); B.signal();
B.signal(); A.signal();
3
SYSTEM MODEL
4
DEADLOCK CHARACTERIZATION
Deadlock can arise if four conditions hold simultaneously.
6
RESOURCE-ALLOCATION GRAPH
(CONT.)
Process
Pi requests instance of Rj
P
i
Rj
Pi is holding an instance of Rj
P
i
Rj 7
EXAMPLE OF A RESOURCE ALLOCATION GRAPH
8
RESOURCE ALLOCATION GRAPH WITH A
DEADLOCK
9
GRAPH WITH A CYCLE BUT NO DEADLOCK
10
BASIC FACTS
11
METHODS FOR HANDLING
DEADLOCKS
12
DEADLOCK PREVENTION
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
14
enumeration
DEADLOCK AVOIDANCE
Requires that the system has some additional a priori information
available
16
SAFE, UNSAFE, DEADLOCK STATE
17
AVOIDANCE ALGORITHMS
18
RESOURCE-ALLOCATION GRAPH
19
UNSAFE STATE IN RESOURCE-ALLOCATION
GRAPH
20
RESOURCE-ALLOCATION GRAPH
ALGORITHM
21
DEADLOCK DETECTION
Detection algorithm
Recovery scheme
22
RESOURCE-ALLOCATION GRAPH AND
WAIT-FOR GRAPH
24
RECOVERY FROM DEADLOCK: PROCESS
TERMINATION
25
RECOVERY FROM DEADLOCK: RESOURCE
PREEMPTION
26