Chapter 3 - Old PPT - Deadlock
Chapter 3 - Old PPT - Deadlock
Chapter 3 - Old PPT - Deadlock
• Resources R1
R2
Mutual exclusion:
only one process at a time can use a resource. ( Resources : not in shared mode )
No preemption:
a resource can be released only voluntarily by the process holding it upon its task
completion.
Circular wait:
there exists a set {P0, P1, …, P0} 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.
System Model
• Resource types R1, R2, . . ., Rm
CPU cycles, memory space, I/O devices
• If all resources have only a single instance then we can define a deadlock detection
algorithm that uses a variant of resource-allocation graph, called a wait for graph.
P5 P5
R1 R3 R4
P2 P3 P1 P2 P3
P1
P4 P4
R2 R5
P1 P1 P1
• Deadlock in both the AND model and the OR
model;
• there are cycles and a knot
P1 P2 P5
P4 P3 P6
Deadlock Handling Strategies
• Deadlock Prevention
• Deadlock Avoidance
• Deadlock Detection
Deadlock Prevention
• We can prevent Deadlock by eliminating any of the
four necessary conditions :
1. Eliminate Mutual Exclusion :
Resouces are sharable and non sharable.
Sharable resources(files) do not require mutually
exclusive access, so not involved in deadlock.
Prb is with non sharable resources (TD,printer) ,they
require ME access.
Therefore it is not possible eliminate Mutual
Exclusion.
2. Eliminate Hold and wait
- If a process P1 holds R1 and wants R2, it must give up R1 first because another process P2
should be able to get it(R1).
- We face with a problem of assigning a TD to P2 after P1 has processed only half the records.
- Therefore this in unacceptable solution.
- Better solution : Each resource will be assigned with a numerical number. A process can
request for the resources only in increasing order of numbering.
Ex : 1≡Card reader
2≡Printer
3≡Plotter
4≡Tape drive
5≡Card punch
• Now the rule is this: processes can request resources whenever they want to, but all requests
must be made in numerical order. A process may request first printer and then a tape drive
(order: 2, 4), but it may not request first a plotter and then a printer (order: 3, 2). The problem
with this strategy is that it may be impossible to find an ordering that satisfies everyone.
Deadlock Avoidance :
• In this approach, resource is allocated to the process
if the resulting global system state is in safe state.
• Global state includes all processes and resources of
DS
• Safe state : if the system can allocate all resources
requested by all processes without entering a
deadlock state.
Because of the following problems, deadlock
avoidance is impractical in DS
1. Every site maintains global state of the system huge
storage requirements and extensive comm costs(every
change must be communicated to every site)
So it becomes impractical
Deadlock Detection :
• Here we need to examine process resource
interaction graph (RAG) to find cycles.
• DD in DS has 2 conditions :
1. Once a cycle is formed in WFG, it persists untill it
is detected and broken
2. Cycle detection can proceed concurrently with
normal system activities.
Therefore it does not have –ve effect on sys
throughput.
Hence we will focus on Deadlock Detection
methods in this chapter.
Issues in Deadlock Detection and Resolution
1. Detection : 2 issues
Centralized
Distributed
Hierarchical
Centralized Control
• One designated site (control site) has the responsibility of
constructing a global WFG and searchs for cycles.
• All decisions are made by the central control site.
• It must maintain the global WFG constantly
or
Periodically – message can be sent to coordinator each
time an arc is added or deleted.
Merits :
1. Simple and easy to implement
2. Deadlock resolution is simple – control site has complete
information about deadlock cycle and hence can resolve
• Suppose machine A has a process P0 which holds
resource S and wants resource R.
• Resource R is held by P1.
• This local graph is maintained on machine A.
• Suppose that another machine B, has a process P2, which
is holding resource T and wants resource S.
• Both of these machines send their graphs to the
coordinator, which maintains the union (overall graph).
• The coordinator sees no cycles. Therefore there are no
deadlocks.
• If a cycle was found (hence a deadlock), the coordinator
would have to make a decision on which machine to
notify for killing a process to break the deadlock
• Suppose two events occur:
• process P1 releases resource R and asks machine B for resource T.
• Two messages are sent to the coordinator:
message 1 (from machine A): releasing R
message 2 (from machine B): waiting for T
This should cause no problems (no deadlock) as no cycles will exist.
However, suppose message 2 arrives first. The coordinator would then
construct the graph shown and detect a deadlock (cycle).
This condition is known as a false deadlock.
A way to fix this is to use Lamport’s algorithm to impose global
time ordering on all machines.
Alternatively, if the coordinator suspects deadlock, it can send a
reliable message to every machine asking whether it has any release
messages. Each machine will then respond with either a release
message or a message indicating that it is not releasing any resources.
Demerits :
• There is one, single point of failure(control site).
De-Merits :
1. More storage : as each site maintains 2 status
tables
One Phase Algorithm(contd)
• It does not detect false deadlocks as it eliminates the
inconsistency in state info by using only info that is
comman to both tables.
• This eliminates inconsistency.
• Ex : If resource table at site S1 indicates that resource
R1 is waited upon by process p2(i.e R1 P2) and the
process table at site S2 indicated that process P2 is
waiting for resource R1 i.e( P2 R1) then edge P2R1
in the constructed WFG reflects the correct system state.
• If either of the entries is missing from resource or
process table , then a request or release message or
release message from S2 to S1 is in transit and
• P2 R1 cannot be ascertained.