0% found this document useful (0 votes)
16 views30 pages

Deadlocks IIITH

Uploaded by

Arza Siddiqui
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views30 pages

Deadlocks IIITH

Uploaded by

Arza Siddiqui
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 30

Handling Deadlocks in

Distributed Systems
Deadlocks
• Deadlocks is a fundamental problem in systems.
• A process may request resources in any order,
which may not be known a priori and a process
can request resource while holding others.
• If the sequence of the allocations of resources
to the processes is not controlled, deadlocks
can occur.
• A deadlock is a state where a set of processes
request resources that are held by other
processes in the set.
Deadlocks
• The problem appears in standard systems too.
• An Operating System can work on this
problem at multiple levels:
– Detect deadlocks
– Recover from deadlocks
– Prevent deadlocks
• Various algorithms exist for these problems.
Example- Deadlock
Process A Process B
• Lock A • Lock B
• Lock B • Lock A
• Transfer • Transfer
• Unlock A • Unlock B
• Unlock B • Unlock A
Lets Recollect Deadlocks
Revision
System Model
• A process can be in two states:
• Running or blocked.
• In the running state (also called active
• state), a process has all the needed resources
and is either executing or is ready for
execution.
• In the blocked state, a process is waiting to
acquire some resource.
Does cycle indicate deadlock?
Wait for Graph
• A wait for graph(WFG) is a graph where nodes
are processes and there are edges from node
P1 to node P2 if P1 is blocked and it is waiting
for P2 to release some resource. A system is
deadlocked iff there is a cycle or knot in the
WFG
• What we study: Detection and Resolution

Detection:
Don’t detect a deadlock when there isnt one
(false deadlocks)
No undetected deadlock
Phantom Deadlocks
• Lock A
• …………
• Unlock A
• Lock B
• …………
• Unlock B

When two nodes execute this; might show a


deadlock
Challenge
• Once a deadlock, the deadlock wont go away
so can take time to detect it. Issue is we might
detect false deadlocks because we can not
capture the global picture locally and while we
wait to understand who is waiting for whom
the dependencies keep changing. The wait for
cycle you might have sketched might be a false
one.
To the Distributed Setting
• A distributed program is composed of a set of
n asynchronous processes p1, p2, . . . , pi, . . . ,
pn that communicate by message passing over
the communication network.
• Without loss of generality we assume that
each process is running on a different
processor.
• The processors do not share a common global
memory and communicate solely by passing
messages over the communication network
To The Distributed Setting
• There is no physical global clock in the system
to which processes have instantaneous access.

• The communication medium may deliver


messages out of order, messages may be lost
garbled or duplicated due to timeout and
retransmission, processors may fail and
communication links may go down.
To The Distributed Setting
• We make the following assumptions:
– The systems have only reusable resources.
– Processes are allowed to make only exclusive
access to resources.
– There is only one copy of each resource

• Hence a system is deadlocked iff there exists a


cycle or knot in WFG
Resource Request Models
The manner in which a task asks for resources can be
Single Resource request Model: can have at most one pending resource
request
AND Resource request Model: Can request multiple resources. Task
resumed only when all are acquired.
Example: (R1 AND R2 AND R3)
OR Resource request Model: Can request multiple resources. Task can
resume when any one of the request resources becomes available
Example: (R1 or R2) or (R1 or R2 or R3)
AND OR Resource request Model: Any combination of AND and OR.
Example: X AND ( Y OR Z)
detecting using WFG does not directly work but algorithms work on
doing repeated OR tests over time (as deadlocks do not go away)
Single Resource Request
Model
Presence of cycle indicates
deadlock?

AND Resource request


Model
If there is a cycle then there is a
deadlock? there is a process
deadlocked then will it be
part of a cycle?
OR Resource request
Model
If there is a cycle then
there is a deadlock?

A knot(K) consists of a set of nodes such that for every node a in K,


all nodes in K and only the nodes in K are reachable from node a.
(SCC with no outgoing edge?)

A knot indicates a deadlock in the OR Model.


Are processes in knot alone deadlocked?
OR Resource request
Model
If there is a cycle then
there is a deadlock?
No, P33, then P32 and
then P11 will run

A knot(K) consists of a set of nodes such that for every node a in K,


all nodes in K and only the nodes in K are reachable from node a.
(SCC with no outgoing edge?)

A knot indicates a deadlock in the OR Model.


Are processes in knot alone deadlocked? No..P44 too is
Hence a system is deadlocked iff there exists a
deadlock or knot in WFG
Deadlock Handling Strategies

 Deadlock Prevention – does not require knowing global


state but is slow and can even have starvation issues
 Deadlock Avoidance –Not popular in DS as expensive.
Requires knowing who has what and what more they may
need
 Deadlock Detection – most popular !as deadlock actually
happening is rare. When you suspect deadlock then you
initiate a deadlock detecton algorithm and then if there is one,
you Prempt certain resources and then restart from that point.

26
Centralized Deadlock-Detection Algorithms
 Ask every process about its wait for
status and create a global wait for
graph. Will this work?

27
Centralized Deadlock-Detection Algorithms
 The Ho-Ramamoorthy Algorithms
 The Two-Phase Algorithm
Deadlocks don’t go away unless broken. Collect status twice. Take
only those dependencies which are present in both. Any issues?
https://www.geeksforgeeks.org/deadlock-detection-in-distributed-
systems-2/

 The One-phase Algorithm


Uses process status table and resource status table . process status
table contains resources that are locked or waited on for each
process. resource status table contains processes using or waiting on
each resource. Takes a dependency as valid only if both tables
indicate it.
28
Centralized Deadlock-Detection Algorithms
 The One-phase Algorithm
process status table: the process’ information where
for each process gives information about resources
held or seeked after.
Resource status table: Processes to which the resource
is allocated to or seeking it
Gather this from all sites and create WFG if tables
gathered from both sites say the same information.
That is site 1 says P waits for R which is on site 2. Site2
also says P requested for R
Can we have false deadlock? 29
Centralized Deadlock-Detection Algorithms
 Consider a false cycle by P1(site1), R1(site 2), P2(site 3)
and R2(site 4) that the two phase algorithm detected
where at
 At site2 we had P1->R1->P2 and
 At site4 we had P2 -> R2 -> P1

When the information from site1 is collected it says either


P1->R1 or R2->P1. Since it wont say both you cannot
construct a cycle though site 2 and site 4 might indicate
P1->R1->P2 and P2 -> R2 -> P1
30

You might also like