0% found this document useful (0 votes)
30 views38 pages

CS3551 Unit 3 Lecture Notes

This document covers Distributed Mutual Exclusion Algorithms and Deadlock Detection in Distributed Systems, focusing on various algorithms such as Lamport’s and Ricart-Agrawala’s. It outlines the objectives, requirements, and performance metrics of mutual exclusion algorithms, emphasizing the importance of fairness, safety, and liveness. Additionally, it discusses the operation of Lamport’s algorithm, including its correctness and performance in ensuring mutual exclusion in distributed systems.

Uploaded by

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

CS3551 Unit 3 Lecture Notes

This document covers Distributed Mutual Exclusion Algorithms and Deadlock Detection in Distributed Systems, focusing on various algorithms such as Lamport’s and Ricart-Agrawala’s. It outlines the objectives, requirements, and performance metrics of mutual exclusion algorithms, emphasizing the importance of fairness, safety, and liveness. Additionally, it discusses the operation of Lamport’s algorithm, including its correctness and performance in ensuring mutual exclusion in distributed systems.

Uploaded by

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

CS3551 - DISTRIBUTED COMPUTING

UNIT – 3 - DISTRIBUTED MUTEX AND DEADLOCK


Distributed Mutual exclusion Algorithms: Introduction – Preliminaries – Lamport’s algorithm –
RicartAgrawala’s Algorithm –– Token-Based Algorithms – Suzuki-Kasami’s Broadcast
Algorithm; Deadlock Detection in Distributed Systems: Introduction – System Model –
Preliminaries – Models of Deadlocks – Chandy-Misra-Haas Algorithm for the AND model and
OR Model.

SUBJECT NAME : CS3551 – DISTRIBUTED SYSTEMS SEM : 05


Unit Lecture
3 – Distributed Mutex and Deadlock 19
No No
Topic Distributed mutual exclusion algorithms: Introduction
Learning Outcome (LO) At the end of this lecture, students will be able Bloom’sKnowledge
to Level
LO1 Explain the Concept of Mutual Exclusion: K2
LO2 Specify the Distributed Systems Characteristics K2
LO3 List various Distributed Mutual Exclusion Algorithms K2
LO4 Analyze Algorithm Performance K2
3.1. DISTRIBUTEDMUTUALEXCLUSIONALGORITHMS:INTRODUCTION

Mutualexclusionisafundamentalproblem indistributedcomputingsystems.
Mutualexclusionensuresthatconcurrentaccessofprocessestoasharedresourceordataisseri
alized,thatis,executedinmutually exclusivemanner.
Mutualexclusioninadistributedsystemstatesthatonlyoneprocessisallowedtoexecutethec
riticalsection (CS)atany giventime.
Messagepassingisthesolemeansforimplementingdistributedmutualexclusion.

Figure1:Threeprocesses accessingasharedresource(criticalsection)simultaneously.

Thereare threebasicapproachesforimplementingdistributedmutualexclusion:

1. Tokenbasedapproach
2. Non-tokenbasedapproach
3. Quorumbasedapproach

CARE COLLEGE OF ENGINEERING R.C.Subashini, AP/AI&DS


CS3551 - DISTRIBUTED COMPUTING

1. In the token-based approach, a unique token (also known as the PRIVILEGE


message) isshared among the sites. A site is allowed to enter its CS if it possesses the
token and
itcontinuestoholdthetokenuntiltheexecutionoftheCSisover.Mutualexclusionisensuredbe
causethetokenis unique.
2. Inthenon-tokenbasedapproach,twoormoresuccessiveroundsofmessagesareexchanged
among the sites to determine which site will enter the CS next. A site enters theCritical
Section (CS) when an assertion, defined on its local variables, becomes true.
MutualExclusionisenforcedbecausetheassertionbecomestrueonlyatonesiteatanygiventi
me
3. In the quorum-based approach, each site requests permission to execute the CS from
asubsetofsites(calledaquorum).Thequorumsareformedinsucha waythatwhentwo sites
concurrentlyrequestaccesstotheCS,onesitereceivesboththerequestsandwhichisresponsibl
etomakesurethatonlyonerequestexecutes theCSatanytime.

OBJECTIVESOFMUTUALEXCLUSIONALGORITHMS
1. Guaranteemutualexclusion(required)
2. Freedomfromdeadlocks(desirable)
3. Freedom from starvation -- every requesting site should get to enter CS in a
finitetime(desirable)
4. Fairness--
requestsshouldbeexecutedintheorderofarrivals,whichwouldbebasedonlogicalcloc
ks (desirable)
5. Faulttolerance--
failureinthedistributedsystemwillberecognizedandthereforenotcauseanyunduly
prolongeddisruptions(desirable)
Primitives
1. Systemmodel
2. Requirementsthatmutualexclusionalgorithms
3. Metricsweuse tomeasuretheperformanceofmutualexclusionalgorithms.

1. SYSTEMMODEL
 The system consists of N sites, S1, S2, ..., SN. We assume that a single process
isrunningoneachsite.
 TheprocessatsiteSiisdenoted bypi.
 A process wishing to enter the CS, requests all other or a subset of processes
bysendingREQUESTmessages,andwaitsforappropriaterepliesbeforeenteringtheCS.Wh
ilewaitingtheprocessisnotallowedtomakefurther requeststoentertheCS.
 Asitecanbeinoneofthefollowingthreestates:
1. RequestingtheCriticalSection.
2. ExecutingtheCriticalSection.
3. NeitherrequestingnorexecutingtheCS(i.e.,idle).
 In the ‘requesting the CS’ state, the site is blocked and can not make further
requestsfortheCS. Inthe‘idle’state,thesiteisexecutingoutsidetheCS.
 Inthetoken-

CARE COLLEGE OF ENGINEERING R.C.Subashini, AP/AI&DS


CS3551 - DISTRIBUTED COMPUTING

basedalgorithms,asitecanalsobeinastatewhereasiteholdingthetokenisexecutingoutsidet
heCS.Suchstateisreferredtoastheidletokenstate.
 Atanyinstant,asitemayhaveseveralpendingrequestsforCS.Asitequeuesuptheserequestsa
ndservesthemoneatatime.

2. REQUIREMENTSOFMUTUALEXCLUSIONALGORITHMS
Amutualexclusionalgorithmshouldsatisfythefollowingproperties:
a. Safety Property: The safety property states that at any instant, only one process
canexecutethecriticalsection.Thisisanessentialpropertyofamutualexclusionalgorithm.
b. Liveness Property: This property states the absence of deadlock and starvation. Two
ormore sites should not endlessly wait for messages which will never arrive. In addition, a
sitemustnotwaitindefinitelytoexecutetheCSwhileothersitesarerepeatedlyexecutingtheCS.Thatis
,everyrequestingsiteshouldgetanopportunitytoexecutetheCSinfinitetime.
c. Fairness: Fairness in the context of mutual exclusion means that each process gets a
fairchancetoexecutetheCS.

Note: The first property is absolutely necessary and the other two properties are
consideredimportantinmutualexclusionalgorithms

3. PERFORMANCEMETRICS

The performance of mutual exclusion algorithms is generally measured by the following


fourmetrics:
a. Messagecomplexity:ItisthenumberofmessagesthatarerequiredperCSexecutionbyasite.
b. Synchronizationdelay:AfterasiteleavestheCS,itisthetimerequiredandbeforethenextsiteenter
s theCS

c. Response time: It is the time interval a request waits for its CS execution to be over
afteritsrequestmessages havebeensentout

Figure2:ResponseTime
d. Systemthroughput: ItistherateatwhichthesystemexecutesrequestsfortheCS.IfSDisthe

CARE COLLEGE OF ENGINEERING R.C.Subashini, AP/AI&DS


CS3551 - DISTRIBUTED COMPUTING

synchronization delay and E is the average critical section execution time, then
thethroughputis givenbythefollowing equation:
SystemThroughput=1/(SD+E)
Generally, the value of a performance metric fluctuates statistically from request to
requestandwegenerally considertheaveragevalueofsuchametric.
Low and High Load Performance: The load is determined by the arrival rate of CS
executionrequests. Twospecial loadingconditions, viz.,“lowload"and“highload".

 Underlowloadconditions,thereisseldommorethanonerequestforthecriticalsectionpresen
tinthesystemsimultaneously.
 Underheavyloadconditions,thereisalwaysa pendingrequestforcriticalsectionatasite.

CARE COLLEGE OF ENGINEERING R.C.Subashini, AP/AI&DS


CS3551 - DISTRIBUTED COMPUTING

Assessment questions to the lecture

Bloom’s
Qn. No. Question Answer Knowledge
Level
To enforce ________________ two functions are provided
enter-critical and exit-critical, where each function takes as Mutual
1 K2
an argument the name of the resource that is the subject of Exclusion
competition.
In five state process model _________ state is a process
that is prepared to execute when given the opportunity.
A) Ready
2 Option A) K2
B) Paused
C) Queued
D) Blocked
A process in the ________ state is moved to the _______
state when the event for which it has been waiting occurs.
A) blocked, blocked/suspend
3 Option C) K2
B) ready, ready/suspend
C) blocked/suspend, ready/suspend
D) ready/suspend, ready

Students have to prepare answers for the following questions at the end of the lecture
Bloom’s
Qn. No Question Marks CO Knowledge
Level
1 What is Mutual Exclusion? 2 3 K1
2 List the requirements of mutual exclusion algorithms. 2 3 K1
3 Specify the Objectives of mutual exclusion? 2 3 K1
4 Describe in detail aboutMutual Exclusion along with 13 3 K2
example.

Reference Book

Author(s) Title of the book Page numbers


Ajay D. Kshemkalyani Distributed Computing Principles, Algorithms
324-356
and MukeshSinghal and Systems

CARE COLLEGE OF ENGINEERING R.C.Subashini, AP/AI&DS


CS3551 - DISTRIBUTED COMPUTING

SUBJECT NAME : CS3551 – DISTRIBUTED SYSTEMS SEM : 05


Unit Lecture
3 – Distributed Mutex and Deadlock 20
No No
Topic Preliminaries – Lamport‘s algorithm
Learning Outcome (LO) At the end of this lecture, students will be able Bloom’sKnowledge
to Level
LO1 Explain the importance of logical clocks in achieving event K1
ordering without the need for a global clock.
LO2 Solve problems related to event ordering using logical clocks K2
and process IDs to ensure consistency across the system.
LO3 Describe the happens-before relation in Lamport’s Algorithm K2
and its significance in event ordering.

LAMPORT’SALGORITHM

ThealgorithmisfairinthesensethatarequestforCSis
executedintheorderoftheirtimestampsandtimeis determinedbylogicalclocks.
WhenasiteprocessesarequestfortheCS,itupdatesitslocalclockandassignstherequestatime
stamp.
ThealgorithmexecutesCSrequestsinthe increasingorderoftimestamps.
EverysiteSikeepsaqueue,request_queuei,

ThisalgorithmrequirescommunicationchannelstodelivermessagestheFIFOorder.
TheAlgorithm

1. Requestingthecriticalsection:
• When a site Si wants to enter the CS, it broadcasts a REQUEST(tsi, i) message to
allother sites and places the request on request_queuei. ((tsi, i) denotes the timestamp
oftherequest.)
• When a site Sj receives the REQUEST(tsi, i) message from site Si, places
siteSi’sRequeston request_queuejand
itreturnsatimestampedREPLYmessagetoSi.

2. Executingthecriticalsection:
SiteSienterstheCSwhen thefollowingtwoconditionshold:
L1:Sihasreceivedamessagewithtimestamplargerthan(tsi,i)fromall othersites.
L2:Si’srequestisatthetopofrequest_queuei.

3. Releasingthecriticalsection:
 SiteSi,uponexitingtheCS,removesitsrequestfromthetopofitsrequestqueueandbroadcasts
atime stampedRELEASEmessagetoallothersites.
 When a site Sj receives a RELEASE message from site Si, it removes Si’s request
fromits request queue. When a site removes a request from its request queue, its
ownrequest may come at the top of the queue, enabling it to enter the CS. Clearly,
whena site receives a REQUEST, REPLY or RELEASE message, it updates its clock
using thetimestampinthemessage.

CARE COLLEGE OF ENGINEERING R.C.Subashini, AP/AI&DS


CS3551 - DISTRIBUTED COMPUTING

Correctness

Theorem1:Lamport’salgorithmachievesmutualexclusion.

Proof:Proofisbycontradiction.SupposetwositesSiandSjareexecutingtheCSconcurrently.Forth
istohappenconditionsL1andL2mustholdatboththesitesconcurrently.This implies that at some
instant in time, say t, both Si and Sj have their own requests at
thetopoftheirrequest_queuesandconditionL1holdatthem.Withoutlossofgenerality,assumethat
Si’s request has smaller timestamp than the request of Sj. From condition L1 and
FIFOpropertyofthecommunicationchannels,itisclearthatatinstantttherequestofSimustbepresent
in request_queuej when Sj was executing its CS. This implies that Sj’s own request isat the
top of its own request_queue when a smaller timestamp request, Si’s request, ispresent in
therequest_queuej –acontradiction!!Hence, Lamport’salgorithmachievesmutualexclusion.

Theorem2:Lamport’salgorithmisfair.

Proof: A distributed mutual exclusion algorithm is fair if the requests for CS are executed
intheorderoftheirtimestamps.Theproofisbycontradiction.SupposeasiteSi’srequesthasasmaller
timestamp than the request of another site Sj and Sj is able to execute the CS
beforeSi.ForSjtoexecutetheCS,ithastosatisfytheconditionsL1andL2.Thisimpliesthatatsomeinst
ant in time say t, Sj has its own request at the top of its queue and it has also received
amessage with timestamp larger than the timestamp of its request from all other sites.
Butrequest_queueat a site is ordered by timestamp, and according to our assumption Si
haslowertimestamp.SoSi’srequestmustbeplacedaheadoftheSj’srequestintherequest_queuej.Thi
sisacontradiction.HenceLamport’salgorithmisafairmutualexclusionalgorithm.

AnExample
InFigures9.3to9.6,weillustratetheoperationofLamport’salgorithm.InFigure9.3,sitesS1andS2
are making requests for the CS and send out REQUEST messages to other sites. Thetime
stamps of the requests are (1, 1) and (1, 2), respectively. In Figure 9.4, both the sites S1and
S2 have received REPLY messages from all other sites. S1 has its request at the top of
itsrequest_queuebutsiteS2doesnothaveitsrequestatthetopofitsrequest_queue.Consequently,site
S1enterstheCS.InFigure9.5,S1exitsandsendsRELEASEmessagestoallother sites. In Figure
9.6, site S2 has received REPLY from all other sites and also received
aRELEASEmessagefromsiteS1.SiteS2updatesitsrequest_queueanditsrequestisnowatthetopofit
s request_queue. Consequently, itenterstheCSnext.

Fig. 1 . Site S1 and S2 requesting for CS

CARE COLLEGE OF ENGINEERING R.C.Subashini, AP/AI&DS


CS3551 - DISTRIBUTED COMPUTING

Performance
foreachCSinvocation
(N-1)
REQUEST(N
-1)REPLY
(N-1)RELEASE,
Total3(N-1)messages,synchronizationdelaySd=averagedelay

CARE COLLEGE OF ENGINEERING R.C.Subashini, AP/AI&DS


CS3551 - DISTRIBUTED COMPUTING

Assessment questions to the lecture

Bloom’s
Qn. No. Question Answer Knowledge
Level
What is the primary purpose of Lamport's Algorithm in
distributed systems?
a) To synchronize physical clocks
1 b) To ensure causal ordering of events Option C) K2
c) To order events using logical clocks
d) To eliminate the need for communication between
processes
In Lamport’s Algorithm, how is a tie resolved when two
events have the same timestamp?
a) By using the process ID
2 Option B) K2
b) By using the physical clock
c) By discarding one of the events
d) By randomly selecting one even
Which of the following is a limitation of Lamport’s
Algorithm?
a) It requires a global physical clock
3 Option C) K2
b) It guarantees causal ordering
c) It does not scale well in large systems
d) It eliminates the need for synchronization

Students have to prepare answers for the following questions at the end of the lecture
Bloom’s
Qn. No Question Marks CO Knowledge
Level
1 Discuss the advantages of using Lamport’s Algorithm in 2 3 K1
distributed systems.
2 Explain the concept of logical clocks in Lamport’s 2 3 K1
Algorithm.
3 Describe the happens-before relation in Lamport’s 2 3 K2
Algorithm and its significance in event ordering.
4 Given a distributed system scenario with multiple 13 3 K3
processes, apply Lamport’s Algorithm to determine the
order of events. Explain each step in detail and discuss the
impact of the algorithm on the system's consistency and
synchronization.

Reference Book
Author(s) Title of the book Page numbers
Ajay D. Kshemkalyani Distributed Computing Principles, Algorithms
324-356
and MukeshSinghal and Systems

CARE COLLEGE OF ENGINEERING R.C.Subashini, AP/AI&DS


CS3551 - DISTRIBUTED COMPUTING

Unit Lecture
3 – Distributed Mutex and Deadlock 21
No No
Topic Ricart-Agrawala algorithm
Learning Outcome (LO) At the end of this lecture, students will be able Bloom’sKnowledge
to Level
LO1 Explain the Ricart-Agrawala algorithm for mutual exclusion K2
in distributed systems.
LO2 Identify the key components and operations involved in the K1
algorithm.
LO3 Analyze the advantages and limitations of the Ricart- K3
Agrawala algorithm.
LO4 Apply the Ricart-Agrawala algorithm to solve mutual K4
exclusion problems in distributed computing.
RICART-AGRAWALAALGORITHM

TheRicart-Agrawalaalgorithm assumesthe communicationchannelsareFIFO.

 Thealgorithmusestwotypesofmessages:REQUESTandREPLY.
 AprocesssendsaREQUESTmessagetoallotherprocessestorequesttheirpermissiontoenterthe
criticalsection.
 AprocesssendsaREPLYmessagetoaprocesstogiveitspermissionto thatprocess.
 Processes use Lamport-style logical clocks to assign a timestampto critical
sectionrequests. Timestamps are used to decide the priority of requests in case of conflict
–if a process pi that is waiting to execute the critical section, receives a
REQUESTmessage from process pj, then if the priority of pj’s request is lower, pi defers
theREPLYtopjandsendsaREPLYmessagetopjonlyafterexecutingtheCSforitspendingreque
st.

 Otherwise, pi sends a REPLY message to pj immediately, provided it is currently


notexecuting the CS. Thus, if several processes are requesting execution of the CS,
thehighestpriorityrequestsucceedsincollectingalltheneededREPLYmessagesandgetstoexe
cutetheCS.

Each process pi maintains the Request-Deferred array, RDi, the size of which is the
sameas the number of processes in the system. Initially, ∀i∀j: RDi[j]=0. Whenever pi defer
therequestsentbypj,itsetsRDi[j]=1andafterithassentaREPLYmessagetopj,itsetsRDi[j]=0.Note:
Deferred–Postponedtherequest/waiting
ALGORITHM

1. Requestingthecriticalsection:
(a) When a site Si wants to enter the CS, it broadcasts a time stamped REQUEST message
toallothersites.
(b) When site Sj receives a REQUEST message from site Si, it sends a REPLY message
toSite Si if site Sj is neither requesting nor executing the CS, or if the site Sj is
requestingAnd Si’s request’s timestamp is smaller than site Sj’s own request’s

CARE COLLEGE OF ENGINEERING R.C.Subashini, AP/AI&DS


CS3551 - DISTRIBUTED COMPUTING

timestamp.otherwise,thereplyis deferredandSjsetsRDj[i]=1

2. Executingthecriticalsection:
(c) SiteSienterstheCSafter
ithasreceivedaREPLYmessagefromeverysiteitsentaREQUESTmessageto.
3. Releasingthecriticalsection:
(d) WhensiteSiexitstheCS,itsendsallthedeferredREPLYmessages:
∀jifRDi[j]=1,thensendaREPLYmessagetoSjandset RDi[j]=0.

Whenasitereceivesamessage,itupdatesitsclockusingthetimestampinthemessage.Also,when a
site takes up a request for the CS for processing, it updates its local clock and assignsa
timestamp to the request. In this algorithm, a site’s REPLY messages are blocked only
bysites which are requesting the CS with higher priority (i.e., smaller timestamp).Thus, when
asite sends out differed REPLY messages, site with the next highest priority request
receivesthe last needed REPLY message and enters the CS. Execution of the CS requests in
thisalgorithmis always intheorderoftheirtimestamps.

AnExample

Figures 9.7 to 9.10 illustrate the operation of Ricart-Agrawala algorithm. In Figure 9.7,
sitesS1andS2aremakingrequestsfortheCSandsendoutREQUESTmessagestoothersites.Thetime
stampsoftherequestsare(2,1)and(1,2),respectively.InFigure9.8,S2hasreceivedREPLYmessages
fromallothersitesandconsequently,itenterstheCS.InFigure9.9,S2exitstheCSandsendsaREPLY
messageto siteS1.InFigure9.10,siteS1hasreceived REPLY fromallothersitesandenters
theCSnext.

CARE COLLEGE OF ENGINEERING R.C.Subashini, AP/AI&DS


CS3551 - DISTRIBUTED COMPUTING

Performance

For each CS execution, Ricart-Agrawala algorithm requires (N − 1) REQUEST messages


and(N−1)REPLYmessages.Thus,itrequires2(N−1)messagesperCSexecution.Synchronizatio
ndelayinthealgorithmisT.

CARE COLLEGE OF ENGINEERING R.C.Subashini, AP/AI&DS


CS3551 - DISTRIBUTED COMPUTING

Assessment questions to the lecture

Bloom’s
Qn. No. Question Answer Knowledge
Level
Which of the following is true about the Ricart-
Agrawala algorithm?
A) It requires a central coordinator.
1 Option C) K2
B) It relies on token passing.
C) It uses timestamp-based requests to ensure fairness.
D) It only works with two processes.
What type of system is the Ricart-Agrawala algorithm
designed for?
A) Centralized systems
2 Option B) K2
B) Distributed systems
C) Multithreaded systems
D) Single-processor systems
What is a primary limitation of the Ricart-Agrawala
algorithm?
A) It causes deadlocks.
3 Option C) K2
B) It lacks fairness.
C) It has high communication overhead.
D) It does not work in distributed systems.

Students have to prepare answers for the following questions at the end of the lecture
Bloom’s
Qn. No Question Marks CO Knowledge
Level
1 Explain the basic working of the Ricart-Agrawala 7 3 K2
algorithm, including the steps involved in requesting and
exiting the critical section.
2 Discuss the advantages and limitations of the Ricart- 5 3 K2
Agrawala algorithm in a distributed computing
environment.
3 Illustrate with an example how the Ricart-Agrawala 8 3 K3
algorithm ensures fairness and avoids deadlock in a
system with multiple processes. Include a detailed
explanation of how timestamp-based requests are
managed.

Reference Book
Author(s) Title of the book Page numbers
Ajay D. Kshemkalyani Distributed Computing Principles, Algorithms
305-317
and MukeshSinghal and Systems

CARE COLLEGE OF ENGINEERING R.C.Subashini, AP/AI&DS


CS3551 - DISTRIBUTED COMPUTING

Unit Lecture
3 – Distributed Mutex and Deadlock 22
No No
Topic Maekawa‘s algorithm
Learning Outcome (LO) At the end of this lecture, students will be able Bloom’sKnowledge
to Level
LO1 Understand Maekawa’s algorithm for achieving mutual K1
exclusion in distributed systems.
LO2 Identify and explain the key components and operations K1
involved in Maekawa’s algorithm.
LO3 Analyze the advantages and limitations of Maekawa’s K2
algorithm.

3.2. MAEKAWA’SALGORITHM
Maekawa’s Algorithm is quorum (subset) based approach to ensure mutual exclusion
indistributed systems. As we know, In permission based algorithms like Lamport’s
Algorithm,Ricart-
AgrawalaAlgorithmetc.asiterequestpermissionfromeveryothersitebutinquorumbased
approach, A site does not request permission from every other site but from a
subsetofsiteswhichis called quorum.
Inthisalgorithm:

Threetypeofmessages(REQUEST,REPLYandRELEASE)areused.
AsitesendaREQUESTmessagetoallothersiteinitsrequestsetorquorumtogettheirpermissio
ntoentercritical section.
AsitesendaREPLYmessagetorequestingsitetogiveitspermissiontoenterthecriticalsection.
AsitesendaRELEASEmessagetoallothersiteinitsrequestsetorquorumuponexitingthecritic
alsection.

Maekawa’s algorithm was the first quorum-based mutual exclusion algorithm. The
requestsets for sites (i.e., quorums) in Maekawa’s algorithm are constructed to satisfy the
followingconditions:

MaekawausedthetheoryofprojectiveplanesandshowedthatN=K(K−1)+1.Thisrelationgives |Ri|
= √N. Since there is at least one common site between the request sets of any
twosites(conditionM1),everypairofsiteshasacommonsitewhichmediatesconflictsbetweenthe
pair. A site can have only one outstanding REPLY message at any time; that is, it
grantspermission to an incoming request if it has not granted permission to some other
site.Therefore,mutualexclusionisguaranteed.Thisalgorithmrequiresdeliveryofmessagestobeinth
eordertheyaresentbetweenverypairofsites.ConditionsM1andM2arenecessaryforcorrectness;wh
ereasconditionsM3andM4provideotherdesirablefeaturestothealgorithm. ConditionM3 states

CARE COLLEGE OF ENGINEERING R.C.Subashini, AP/AI&DS


CS3551 - DISTRIBUTED COMPUTING

that the size of the requests sets of all sites must be equalimplying that all sites should have to
do equal amount of work to invoke mutual
exclusion.ConditionM4enforcesthatexactlythesamenumberofsitesshouldrequestpermissionfro
manysiteimplyingthatallsiteshave“equalresponsibility”ingrantingpermissiontoothersites.

ALGORITHM

InMaekawa’salgorithm,asiteSiexecutesthefollowingstepstoexecutetheCS.
1. Requestingthecriticalsection
(a) A site Si requests access to the CS by sending REQUEST(i) messages to all sites
initsrequest set Ri.
(b) WhenasiteSjreceivestheREQUEST(i)message,itsendsaREPLY(j)messagetoSiprovi
ded it hasn’t sent a REPLY message to a site since its receipt of the last
RELEASEmessage.Otherwise,itqueues uptheREQUEST(i)for laterconsideration.
2. Executingthecriticalsection
(c) SiteSiexecutes
theCSonlyafterithasreceivedaREPLYmessagefromeverysiteinRi.
3. Releasingthecriticalsection
(d) After the execution of the CS is over, site Si sends a RELEASE (i) message
toeverysiteinRi.
(e)When a site Sj receives a RELEASE(i) message from site Si, it sends a
REPLYmessagetothenextsitewaitinginthequeueanddeletesthatentryfromthe
queue.
Ifthequeueisempty,thenthesiteupdatesitsstateto reflectthatithasnotsentout
anyREPLYmessagesincethe receiptofthelastRELEASEmessage.

Correctness
Theorem3:Maekawa’salgorithmachievesmutualexclusion.

Proof: Proof is by contradiction. Suppose two sites Si and Sj are concurrently executing
theCS. This means site Si received a REPLY message from all sites in Ri and concurrently
site
SjwasabletoreceiveaREPLYmessagefromallsitesinRj.IfRi∩Rj={Sk},thensiteSkmusthavesent
REPLYmessagestobothSiandSjconcurrently,which is acontradiction. 2

Performance
Note that the size of a request set is √N. Therefore, an execution of the CS requires
√NREQUEST,√N REPLY, and √N RELEASE messages, resulting in 3√N messages per CS
execution.Synchronizationdelayinthisalgorithm
is2T.ThisisbecauseafterasiteSiexitstheCS,itfirstreleases all the sites in Ri and then one of
those sites sends a REPLY message to the next sitethat executes the CS. Thus, two sequential
message transfers are required between
twosuccessiveCSexecutions.Asdiscussednext,Maekawa’salgorithmisdeadlock-
prone.Measures tohandledeadlocks requireadditionalmessages.

ProblemofDeadlocks

CARE COLLEGE OF ENGINEERING R.C.Subashini, AP/AI&DS


CS3551 - DISTRIBUTED COMPUTING

Maekawa’s algorithm can deadlock because a site is exclusively locked by other sites
andrequests are not prioritized by their timestamps [14, 22]. Thus, a site may send a
REPLYmessagetoasite andlater forceahigherpriorityrequestfromanother sitetowait.
Withoutthelossofgenerality,assumethreesitesSi,Sj,andSksimultaneouslyinvokemutualexclusio
n. Suppose Ri ∩ Rj= {Sij}, Rj∩ Rk= {Sjk}, and Rk∩ Ri= {Ski}. Since sites do not
sendREQUEST messages to the sites in their request sets in any particular order and
messagedelays are arbitrary, the following scenario is possible: Sij has been locked by Si
(forcing Sj towait at Sij), Sjk has been locked by Sj(forcing Sk to wait at Sjk), and Ski has
been locked bySk(forcingSito waitatSki).ThisstaterepresentsadeadlockinvolvingsitesSi,
Sj,andSk.

HandlingDeadlocks
Maekawa’salgorithmhandlesdeadlocksbyrequiringasitetoyieldalockifthetimestampofits
request is larger than the timestamp of some other request waiting for the same
lock(unlesstheformerhassucceededinacquiring
locksonalltheneededsites).Asitesuspectsadeadlock (and initiates message exchanges to
resolve it) whenever a higher priority requestarrive sand waits at a site because the site has
sent a REPLY message to a lower priorityrequest. Deadlockhandling requires thefollowing
threetypes ofmessages:

Deadlockhandlingrequiresthe followingthreetypesofmessages:

FAILED:AFAILEDmessagefromsiteSitositeSjindicatesthatSicannotgrantSj’srequestbecauseit
hascurrentlygrantedpermissiontoasitewithahigherpriority request.
INQUIRE:AnINQUIREmessagefromSitoSjindicatesthatSiwouldliketofindoutfrom
Sjifithassucceededinlocking allthesitesinits requestset.
YIELD: A YIELD message from site Si to Sj indicates that Si is returning the permission to
Sj(toyieldtoahigherpriority requestatSj).

CARE COLLEGE OF ENGINEERING R.C.Subashini, AP/AI&DS


CS3551 - DISTRIBUTED COMPUTING

Assessment questions to the lecture

Bloom’s
Qn. No. Question Answer Knowledge
Level
What is the primary advantage of Maekawa’s algorithm
over other distributed mutual exclusion algorithms?
 A) It eliminates the need for timestamps.
1 Option B) K2
 B) It requires fewer messages for mutual exclusion.
 C) It prevents all types of deadlocks.
 D) It does not require a quorum.
nMaekawa’s algorithm, what is a quorum?
 A) A central coordinator.
 B) A set of processes with whom communication is
2 Option B) K2
necessary.
 C) A token that grants access to the critical section.
 D) A set of messages exchanged between processes.
Which of the following is a potential issue with
Maekawa’s algorithm?
 A) High communication overhead.
3 Option C) K2
 B) Lack of fairness in resource allocation.
 C) Complexity in designing quorums.
 D) Requirement for a central server.

Students have to prepare answers for the following questions at the end of the lecture
Bloom’s
Qn. No Question Marks CO Knowledge
Level
1 Define a quorum in the context of Maekawa’s algorithm. 2 3 K1
2 Explain the steps involved in Maekawa’s algorithm for 13 3 K2
mutual exclusion.
3 Discuss the advantages and limitations of Maekawa’s 6 3 K2
algorithm in distributed systems.

Reference Book
Author(s) Title of the book Page numbers
Ajay D. Kshemkalyani Distributed Computing Principles, Algorithms
311-315
and MukeshSinghal and Systems

CARE COLLEGE OF ENGINEERING R.C.Subashini, AP/AI&DS


CS3551 - DISTRIBUTED COMPUTING

Unit Lecture
3 – Distributed Mutex and Deadlock 23
No No
Topic SUZUKI-KASAMI’SBROADCASTALGORITHM
Learning Outcome (LO) At the end of this lecture, students will be able Bloom’sKnowledge
to Level
LO1 Understand Suzuki-Kasami’s broadcast algorithm for mutual K1
exclusion in distributed systems.
LO2 Identify and explain the key components and operations K2
involved in Suzuki-Kasami’s algorithm.
LO3 Analyze the advantages and limitations of Suzuki-Kasami’s K2
algorithm.

3.5 SUZUKI-KASAMI’SBROADCASTALGORITHM

 Suzuki–Kasamialgorithmisatoken-
basedalgorithmforachievingmutualexclusionindistributedsystems.
 Intoken-basedalgorithms,Asiteisallowed
toenteritscriticalsectionifitpossessestheuniquetoken.
 Non-token-basedalgorithmsusestimestamptoorderrequestsforthecriticalsectionwhereas
sequencenumber is usedintokenbasedalgorithms.

 Eachrequestforcriticalsectioncontainsa sequence
number.Thissequencenumberisusedtodistinguishold andcurrentrequests.

CARE COLLEGE OF ENGINEERING R.C.Subashini, AP/AI&DS


CS3551 - DISTRIBUTED COMPUTING

CARE COLLEGE OF ENGINEERING R.C.Subashini, AP/AI&DS


CS3551 - DISTRIBUTED COMPUTING

In Suzuki-Kasami’s algorithm if a site that wants to enter the CS, does not have the token,
itbroadcasts a REQUEST message for the token to all other sites. A site which possesses
thetoken sends it to the requesting site upon the receipt of its REQUEST message. If a
sitereceives a REQUEST message when it is executing the CS, it sends the token only after it
hascompletedtheexecutionoftheCS.

The basic idea underlying this algorithm may sound rather simple, however, there are
thefollowing twodesignissuesmustbeefficiently addressed:

1. HowtodistinguishinganoutdatedREQUESTmessagefromacurrentREQUESTmessage:

Due to variable message delays, a site may receive a token request message after
thecorrespondingrequesthasbeensatisfied.Ifasitecannotdeterminediftherequestcorresponding
to a token request has been satisfied, it may dispatch the token to a site thatdoes not need it.
This will not violate the correctness; however, this may seriously degradethe performance by
wasting messages and increasing the delay at sites that are
genuinelyrequestingthetoken.Therefore,appropriatemechanismsshouldimplementedtodetermi
neifatokenrequestmessageisoutdated.

2. How to determine which site has an outstanding request for the CS: After a site
hasfinished the execution of the CS, it must determine what sites have an outstanding
requestfor the CS so that the token can be dispatched to one of them. The problem is
complicatedbecause when a site Si receives a token request message from a site Sj, site Sj
may have anoutstandingrequestfortheCS.However,afterthe
correspondingrequestfortheCShasbeensatisfied at Sj, an issue is how to inform site Si (and all
other sites) efficiently about it.Outdated REQUEST messagesare distinguishedfrom
currentREQUEST messagesin thefollowingmanner:AREQUEST
messageofsiteSjhastheformREQUEST(j,n) wheren (n=1,2,
...)isasequencenumberwhichindicatesthatsiteSjisrequestingitsnthCSexecution.
A site Si keeps an array of integers RNi[1..N] where RNi[j] denotes the largest
sequencenumber received in a REQUEST message so far from site Sj. When site Si receives
a REQUEST(j, n)message, it sets RNi[j]:=max(RNi[j], n). Thus, when a site Si receives a
REQUEST (j,
n)message,therequestisoutdatedifRNi[j]>n.SiteswithoutstandingrequestsfortheCSare
determinedinthefollowingmanner:Thetokenconsistsofaqueueofrequestingsites,Q,andanarrayof
integersLN[1..N],whereLN[j]isthesequencenumberoftherequestwhichsiteSjexecuted most
recently. After executing its CS, a site Si updates LN[i]:=RNi[i] to indicate
thatitsrequestcorrespondingtosequencenumberRNi[i]hasbeenexecuted.TokenarrayLN[1..N]per
mitsasitetodetermineifasitehasanoutstandingrequestfortheCS.NotethatatsiteSiifRNi[j]=LN[j]+
1,thensiteSjiscurrentlyrequestingtoken.AfterexecutingtheCS,asitechecksthis condition for all
the j’ s to determine all the sites which are requesting the token
andplacestheirid’sinqueueQiftheseid’sarenotalreadypresentintheQ.Finally,thesitesendsthetoke
ntothesitewhoseidis atthehead oftheQ.

CARE COLLEGE OF ENGINEERING R.C.Subashini, AP/AI&DS


CS3551 - DISTRIBUTED COMPUTING

ALGORITHM

1. Requestingthecriticalsection
(a) If requesting site Si does not have the token, then it increments its
sequencenumber, RNi[i], and sends a REQUEST(i, sn) message to all other sites.
(‘sn’ is theupdatedvalueofRNi[i].)
(b) When a site Sj receives this message, it sets RNj[i] to max(RNj[i], sn). If Sj has
theidletoken,thenitsendsthetokentoSiifRNj[i]=LN[i]+1.

2. Executingthecriticalsection
(c) SiteSiexecutestheCSafterithasreceivedthetoken.

3. Releasing the critical section Having finished the execution of the CS, site Si takes
thefollowingactions:
(d) ItsetsLN[i]elementofthetokenarrayequaltoRNi[i].
(e) For every site Sj whose id is not in the token queue, it appends its id to the
tokenqueueifRNi[j]=LN[j]+1.
(f) If the token queue is nonempty after the above update, Si deletes the top site
idfrom the token queue and sends the token to the site indicated by the id. Thus,
afterexecuting the CS, a site gives priority to other sites with outstanding requests for
theCS (over its pending requests for the CS). Note that Suzuki-Kasami’s algorithm is
notsymmetric because a site retains the token even if it does not have a request for
theCS, which is contrary to the spirit of Ricart and Agrawala’s definition of
symmetricalgorithm:“nositepossessestherighttoaccessitsCSwhenithasnotbeenrequeste
d”.

Correctness
Mutualexclusionisguaranteedbecausethereisonlyonetokeninthesystemandasiteholdsthetokendur
ing theCSexecution.

CARE COLLEGE OF ENGINEERING R.C.Subashini, AP/AI&DS


CS3551 - DISTRIBUTED COMPUTING

Assessment questions to the lecture

Bloom’s
Qn. No. Question Answer Knowledge
Level
What is the primary mechanism used by Suzuki-
Kasami’s algorithm to grant access to the critical
section?
1  A) Central coordinator Option B) K2
 B) Token passing
 C) Timestamp comparison
 D) Quorum-based decision
In Suzuki-Kasami’s algorithm, what happens if a
process does not have the token but wants to enter the
critical section?
 A) It waits for the token to be randomly assigned.
2  B) It broadcasts a request message to all other Option B) K2
processes.
 C) It generates a new token.
 D) It sends a direct request to the current token
holder.
Which of the following is a potential disadvantage of
Suzuki-Kasami’s algorithm?
 A) High message complexity
3 Option C) K2
 B) No fairness in resource allocation
 C) Potential deadlock if the token is lost
 D) Requires communication with all processes

Students have to prepare answers for the following questions at the end of the lecture
Bloom’s
Qn. No Question Marks CO Knowledge
Level
1 What is the role of the token in Suzuki-Kasami’s 2 1 K1
broadcast algorithm?
2 Explain the steps involved in Suzuki-Kasami’s algorithm 2 1 K2
when a process wants to enter the critical section.
3 Discuss the advantages and limitations of using Suzuki- 2 1 K2
Kasami’s algorithm in a distributed system.

Reference Book
Author(s) Title of the book Page numbers
Ajay D. Kshemkalyani Distributed Computing Principles, Algorithms
320-324
and MukeshSinghal and Systems

CARE COLLEGE OF ENGINEERING R.C.Subashini, AP/AI&DS


CS3551 - DISTRIBUTED COMPUTING

Unit Lecture
3 – Distributed Mutex and Deadlock 24
No No
Topic Deadlock Detection in Distributed Systems: Introduction
Learning Outcome (LO) At the end of this lecture, students will be able Bloom’sKnowledge
to Level
LO1 Understand the concept of deadlock in distributed systems K1
and its implications.
LO2 Identify and explain the key factors involved in deadlock K2
detection.
LO3 Analyze various algorithms used for deadlock detection in K2
distributed systems.

3.6. DEADLOCK DETECTION IN


DISTRIBUTED SYSTEMSINTRODUCTION
A deadlock is a condition where a process cannot proceed because it needs
toobtainaresourceheldbyanotherprocessandititselfisholdingaresourcethattheother
process needs.
Wecanconsidertwotypes of deadlock:
1. Communication deadlock occurs when process A is trying to send
amessage to process B, which is trying to send a message to process
Cwhich is trying tosendamessagetoA.
2. A resource deadlock occurs when processes are trying to get
exclusiveaccess to devices, files, locks, servers, or other resources. We
will notdifferentiate between these types of deadlock since we can
considercommunicationchannelstoberesourceswithoutlossofgenerality.

“A deadlock can be defined as a condition where a set of processes request resources


thatareheldbyotherprocessesintheset.”

Deadlock deals with various componentslike deadlock prevention, deadlock


avoidanceotherthandeadlockdetection.
 Deadlockpreventioniscommonlyachievedbyeitherhavingaprocessacquirealltheneeded
resources simultaneously before it begins execution or bypre-empting
aprocessthatholdtheneededresource.
 In the deadlock avoidance approach to distributed system, a resource is granted to
aprocessiftheresulting globalsystemis safe.
 Deadlock detection requires an examination of the status of the process-
resourcesinteractionforthepresenceofadeadlockcondition.Toresolvethedeadlock,wehav
etoabortadeadlockedprocess.

CARE COLLEGE OF ENGINEERING R.C.Subashini, AP/AI&DS


CS3551 - DISTRIBUTED COMPUTING

Problem Example:

Problem Statement: Consider a distributed system with three processes (P1, P2, P3) and three
resources (R1, R2, R3). The following resource allocation and request scenario is given:

 P1 holds R1 and requests R2.


 P2 holds R2 and requests R3.
 P3 holds R3 and requests R1.

Using a centralized deadlock detection algorithm, demonstrate how the deadlock is detected.

Solution:

1. Constructing the Wait-For Graph:


o Nodes represent processes, and directed edges represent the request from one
process to another.
o Create edges: P1 → P2, P2 → P3, P3 → P1.
2. Cycle Detection:
o The graph forms a cycle (P1 → P2 → P3 → P1), indicating that a deadlock
exists.
3. Conclusion: The centralized algorithm successfully detects the deadlock by identifying
the cycle in the wait-for graph. Appropriate recovery mechanisms, such as aborting a
process or preempting resources, can be employed to resolve the deadlock.

Advantages and Limitations:

Advantages:

 Centralized Detection: Simplifies the detection process by collecting all information in


one place, making it easier to analyze.
 Distributed Detection: Eliminates a single point of failure and scales better in large
systems.
 Hierarchical Detection: Balances communication overhead and detection speed,
making it suitable for large, complex systems.

Limitations:

 Communication Overhead: In distributed detection, the communication required to


share state information can be significant.
 False Positives/Negatives: Algorithms must handle incorrect detection, which can lead
to unnecessary process termination or undetected deadlocks.
 Complexity: The complexity of detecting deadlocks increases in distributed systems
due to the lack of a global state and the possibility of message delays.

CARE COLLEGE OF ENGINEERING R.C.Subashini, AP/AI&DS


CS3551 - DISTRIBUTED COMPUTING

Assessment questions to the lecture

Bloom’s
Qn. No. Question Answer Knowledge
Level
Which condition is NOT necessary for a deadlock to
occur?
 A) Mutual exclusion
1 Option C) K2
 B) Hold and wait
 C) Preemption
 D) Circular wait
In a distributed system, what does a cycle in a wait-for
graph indicate?
 A) Resource contention
2  B) High communication overhead Option C) K2
 C) Deadlock
 D) Resource availability

Which of the following is a potential disadvantage of


centralized deadlock detection?
 A) Simplified detection
3 Option B) K2
 B) Single point of failure
 C) High scalability
 D) Low communication overhead

Students have to prepare answers for the following questions at the end of the lecture
Bloom’s
Qn. No Question Marks CO Knowledge
Level
1 Define deadlock in the context of distributed systems. 2 1 K1
2 Explain the four conditions necessary for deadlock to 2 1 K2
occur in a distributed system.
3 Discuss the advantages and limitations of centralized 2 1 K2
deadlock detection in distributed systems.

Reference Book
Author(s) Title of the book Page numbers
Ajay D. Kshemkalyani Distributed Computing Principles, Algorithms
273-277
and MukeshSinghal and Systems

CARE COLLEGE OF ENGINEERING R.C.Subashini, AP/AI&DS


CS3551 - DISTRIBUTED COMPUTING

Unit Lecture
3 – Distributed Mutex and Deadlock 25
No No
Topic Deadlock - System model
Learning Outcome (LO) At the end of this lecture, students will be able Bloom’sKnowledge
to Level
LO1 Understand the system model used to describe and analyze K1
deadlocks in distributed systems.
LO2 Identify and explain the key factors involved in deadlock K2
formation in distributed systems.
LO3 Analyze how the system model influences deadlock detection K2
and prevention strategies.

3.7. SYSTEMMODEL

 Adistributedsystemconsistsofasetofprocessorsthatareconnectedbyacommunication
network.
 Thecommunicationdelayisfinitebutunpredictable.
 Adistributed
programiscomposedofasetofnasynchronousprocessesp1,p2,...,pi,...,pnthatcommunicate
sbymessagepassingoverthecommunication network.
 Withoutlossofgeneralityweassumethateachprocessisrunningonadifferentprocessor.
 Theprocessorsdonotshareacommonglobalmemoryandcommunicatesolelybypassing
messagesoverthecommunicationnetwork.
 The communication medium may deliver messages out of order, messages may
belostgarbledorduplicatedduetotimeoutandretransmission,processorsmayfailandcomm
unication links may godown.
 The system can be modelled as a directed graph in which vertices represent
theprocesses andedgerepresentunidirectionalcommunicationchannels.

Wemakethefollowingassumptions:

• Thesystemshaveonlyreusable resources.
• Processesareallowed tomakeonlyexclusiveaccesstoresources.
• Thereisonlyone copy ofeachresource.
A process can be in two states: running or blocked. In the running state (also called
activestate),aprocesshasalltheneededresourcesandiseitherexecutingorisreadyforexecution.Inthe
blockedstate,aprocess iswaiting toacquiresomeresource.

Wait-For-Graph(WFG)

 Indistributedsystems,thestateofthesystemcanbemodelledbydirectedgraph,calleda
waitforgraph(WFG).
 In a WFG, nodes are processes and there is a directed edge from node P1 to mode
P2ifP1is blockedandis waiting forP2toreleasesomeresource.
 Asystemisdeadlockedifandonlyifthereexistsadirected cycle orknotintheWFG.

CARE COLLEGE OF ENGINEERING R.C.Subashini, AP/AI&DS


CS3551 - DISTRIBUTED COMPUTING

Figure 10.1 shows a WFG, where process P11 of site 1 has an edge to process P21 of site
1andP32ofsite2iswaitingforaresourcewhichiscurrentlyheldbyprocessP21.Atthesametime
process P32 is waiting on process P33 to release a resource. If P21 is waiting on processP11,
then processes P11, P32 and P21 form a cycle and all the four processes are involved
inadeadlock depending upontherequestmodel.

CARE COLLEGE OF ENGINEERING R.C.Subashini, AP/AI&DS


CS3551 - DISTRIBUTED COMPUTING

Assessment questions to the lecture

Bloom’s
Qn. No. Question Answer Knowledge
Level
Which of the following is NOT a condition necessary for
a deadlock to occur?
 A) Mutual exclusion
1 Option B) K2
 B) Preemption
 C) Hold and wait
 D) Circular wait
In the context of deadlock detection, what does a cycle
in the wait-for graph indicate?
 A) Resource availability
2 Option C) K2
 B) System efficiency
 C) Potential deadlock
 D) Safe state
Which resource type is typically considered in deadlock
analysis?
 A) Consumable resources only
3 Option C) K2
 B) Reusable resources only
 C) Both reusable and consumable resources
 D) Neither reusable nor consumable resources

Students have to prepare answers for the following questions at the end of the lecture
Bloom’s
Qn. No Question Marks CO Knowledge
Level
1 Define deadlock. 2 3 K1
2 What is the role of the wait-for graph in deadlock 2 3 K1
detection?
3 Describe the system model used to analyze deadlocks in 13 3 K2
distributed systems. How does it help in detecting and
preventing deadlocks?
4 Given a distributed system with four processes and four 13 3 K3
resources, construct a request-allocation graph based on a
given scenario. Analyze the graph to determine if the
system is in a deadlock state. Discuss how deadlock can
be prevented or detected using the system model, and
explain the potential challenges in implementing these
strategies in a large distributed system.

Reference Book
Author(s) Title of the book Page numbers
Ajay D. Kshemkalyani Distributed Computing Principles, Algorithms
256
and MukeshSinghal and Systems

CARE COLLEGE OF ENGINEERING R.C.Subashini, AP/AI&DS


CS3551 - DISTRIBUTED COMPUTING

Unit Lecture
3 – Distributed Mutex and Deadlock 26
No No
Topic Models of deadlocks
Learning Outcome (LO) At the end of this lecture, students will be able Bloom’sKnowledge
to Level
LO1 Understand the different models of deadlocks in distributed K1
systems.
LO2 Identify and explain the key factors involved in each deadlock K2
model.
LO3 Analyze how different models impact deadlock detection, K4
prevention, and resolution strategies.
LO4 Apply the knowledge of deadlock models to solve problems K3
in distributed systems.

MODELSOFDEADLOCKS

 Distributedsystemsallowmanykindsofresourcerequests.Aprocessmightrequireasinglere
sourceoracombinationofresourcesforitsexecution.Thissectionintroducesa hierarchy of
request models starting with very restricted forms to the ones with norestrictions
whatsoever. This hierarchy shall be used to classify deadlock
detectionalgorithmsbasedonthecomplexityoftheresourcerequeststheypermit.

TheSingleResourceModel
Thesingleresourcemodelisthesimplestresourcemodelinadistributedsystem,hereaprocess
canhaveatmostoneoutstandingrequestforonlyoneunitofaresource.Sincethe
maximumout-
degreeofanodeinaWFGforthesingleresourcemodelcanbe1,thepresenceofacycleintheWFGshalli
ndicatethatthereisadeadlock.Inalatersection,analgorithmtodetectdeadlockinthesingleresource
modelispresented.

TheANDModel
In the AND model, a process can request for more than one resource simultaneously
andthe
request is satisfied only after all the requested resources are granted to the process.
Therequestedresourcesmayexistatdifferentlocations.TheoutdegreeofanodeintheWFGforAND
model can be more than 1. The presence of a cycle in the WFG indicates a deadlock inthe
AND model. Each node of the WFG in such a model is called an AND node. Consider
theexampleWFGdescribedintheFigure10.1.ProcessP11hastwo outstandingresourcerequests. In
case of the AND model, P11shall become active from idle state only after boththe resources
are granted. There is a cycle P11->P21->P24->P54->P11 which corresponds
toadeadlocksituation.
In the AND model, if a cycle is detected in the WFG, it implies a deadlock but not vice
versa.Thatis,aprocessmaynotbeapartofacycle,itcanstillbedeadlocked.ConsiderprocessP44inFig
ure10.1.ItisnotapartofanycyclebutisstilldeadlockedasitisdependentonP24whichisdeadlocked.S
inceinthesingle-
resourcemodel,aprocesscanhaveatmostoneoutstandingrequest,theANDmodelismoregeneraltha
nthesingle-resourcemodel.

CARE COLLEGE OF ENGINEERING R.C.Subashini, AP/AI&DS


CS3551 - DISTRIBUTED COMPUTING

CARE COLLEGE OF ENGINEERING R.C.Subashini, AP/AI&DS


CS3551 - DISTRIBUTED COMPUTING

TheORModel
In the OR model, a process can make a request for numerous resources simultaneously andthe
request is satisfied if any one of the requested resources is granted. The
requestedresourcesmayexistatdifferentlocations.IfallrequestsintheWFGareORrequests,thenthe
nodes are called OR nodes. Presence of a cycle in the WFG of an OR model does not imply
adeadlock in the OR model. To make it more clear, consider Figure 10.1. If all nodes are
ORnodes, then process P11 is not deadlocked because once process P33 releases its
resources,P32 shall become active as one of its requests is satisfied. After P32 finishes
execution andreleases its resources,process P11 can continuewithits processing.
IntheORmodel,thepresenceofaknotindicatesadeadlock.InaWFG,avertexvisinaknotifforallu::ui
sreachablefromv:visreachablefromu.Nopathsoriginatingfromaknotshallhavedeadends.
AdeadlockintheORmodelcan beintuitivelydefinedasfollows:AprocessPiisblockedifithas a
pending OR request to be satisfied. With every blocked process, there is an
associatedsetofprocessescalleddependentset.Aprocessshallmovefromidletoactivestateonreceivi
ngagrantmessagefromanyoftheprocessesinitsdependentset.Aprocessispermanentlyblockedifitne
verreceivesagrantmessagefromanyoftheprocessesinitsdependentset.Intuitively,asetofprocessesS
isdeadlockedifalltheprocessesinSarepermanentlyblocked.Toformallystatethatasetofprocessesis
deadlocked,thefollowingconditionsholdtrue:

1. Eachoftheprocessisthe setSisblocked,
2. Thedependentsetforeach process inSisasubsetofS,and
3. Nograntmessageisintransitbetweenanytwo processesinsetS.

Wenowshowthatasetofprocesses SshallremainpermanentlyblockedintheORmodelif
the above conditions are met. A blocked process P is the set S becomes active only
afterreceiving a grant message from a process in its dependent set, which is a subset of S.
Notethat no grant message can be expected from any process in S because they are all
blocked.Also, the third condition states that no grant messages in transit between any two
processesinset S. So,all theprocessesinset Sarepermanently blocked.
Hence, deadlock detection in the OR model is equivalent to finding knots in the graph.
Notethat,therecanbeaprocessdeadlockedwhichisnotapartofaknot.ConsidertheFigure10.1where
P44 can be deadlocked even though it is not in a knot. So, in an OR model, a
blockedprocessPisdeadlockedifitiseither inaknotor itcanonlyreachprocesses onaknot.

TheAND-ORModel
A generalization of the previous two models (OR model and AND model) is the AND-
ORmodel. In the AND-OR model, a request may specify any combination of and andor in
theresourcerequest.Forexample,intheAND-
ORmodel,arequestformultipleresourcescanbeoftheformxand(yorz).Therequestedresourcesma
yexistatdifferentlocations.Todetectthepresenceofdeadlocksinsuchamodel,thereisnofamiliarcon
structofgraphtheoryusingWFG. Since a deadlock is a stable property (i.e., once it exists, it
does not go away by itself),this property can be exploited and a deadlock in the AND-OR
model can be detected byrepeated application of the test for OR-model deadlock. However,
this is a very inefficientstrategy. EfficientalgorithmstodetectdeadlocksinAND-
ORmodelarediscussedinHerman

CARE COLLEGE OF ENGINEERING R.C.Subashini, AP/AI&DS


CS3551 - DISTRIBUTED COMPUTING

UnrestrictedModel
In the unrestricted model, no assumptions are made regarding the underlying structure
ofresourcerequests.Inthismodel,onlyoneassumptionthatthedeadlockisstableismadeandhence it
is the most general model. This way of looking at the deadlock problem helps inseparation of
concerns: Concerns about properties of the problem (stability and deadlock)are separated
fromunderlyingdistributed systems computations (e.g., message passingversus synchronous
communication). Hence, these algorithms can be used to detect otherstable properties as they
deal with this general model. But, these algorithms are of moretheoretical value for
distributed systems since no further assumptions are made about
theunderlyingdistributedsystemscomputationswhichleadstoagreatdealof overhead.

CARE COLLEGE OF ENGINEERING R.C.Subashini, AP/AI&DS


CS3551 - DISTRIBUTED COMPUTING

Assessment questions to the lecture

Bloom’s
Qn. No. Question Answer Knowledge
Level
Which model requires a process to wait until all
requested resources are available?

 A) OR Model
1  B) AND Model Option B) K2
 C) AND-OR Model
 D) Resource Allocation Graph Model

In which model does a cycle in the wait-for graph


always indicate a deadlock?

 A) AND Model
2  B) OR Model Option A) K2
 C) AND-OR Model
 D) None of the above

Which of the following models is more flexible but


increases the complexity of deadlock detection?

 A) AND Model
3  B) OR Model Option B) K2
 C) Resource Allocation Graph Model
 D) Wait-for Graph Model

Students have to prepare answers for the following questions at the end of the lecture
Bloom’s
Qn. No Question Marks CO Knowledge
Level
1 Define the Resource Allocation Graph (RAG) model in 2 3 K1
the context of deadlocks.
2 Explain the differences between the AND model and the 2 3 K1
OR model for deadlocks in distributed systems.
3 Describe in detail the various models of Deadlock. 13 3 K2
Reference Book
Author(s) Title of the book Page numbers
Ajay D. Kshemkalyani Distributed Computing Principles, Algorithms
265
and MukeshSinghal and Systems

CARE COLLEGE OF ENGINEERING R.C.Subashini, AP/AI&DS


CS3551 - DISTRIBUTED COMPUTING

Unit Lecture
3 – Distributed Mutex and Deadlock 27
No No
Topic Chandy-Misra-Haas Algorithm for the AND model
Learning Outcome (LO) At the end of this lecture, students will be able Bloom’sKnowledge
to Level
LO1 Understand the Chandy-Misra-Haas algorithm for deadlock K1
detection in distributed systems.
LO2 Identify key factors and points related to the AND model of K2
the Chandy-Misra-Haas algorithm.
LO3 Apply the algorithm to solve problems involving deadlock K3
detection in distributed computing environments.

CHANDY-MISRA-HAASALGORITHMFORTHEAND MODEL
Chandy-Misra-Haas’s distributed deadlock detection algorithmfor ANDmodel that is based
on edge-chasing. The algorithm uses a special message called
probe,whichisatriplet(i,j,k),denotingthatitbelongstoadeadlockdetectioninitiatedforprocessPian
ditis being sentbythehomesiteofprocess Pj to the home site of process Pk. A probe message
travels along the edges of theglobal WFG graph, and a deadlock is detected when a probe
message returns to the processthatinitiatedit.
A process Pj is said to be dependent on another process Pk if there exists a sequence
ofprocesses Pj,Pi1, Pi2, ..., Pim, Pk such that each process except Pk in the sequence is
blockedand each process, except the Pj, holds a resource for which the previous process in
thesequence is waiting. Process Pj is said to belocally dependent upon process Pk if Pj
isdependentuponPkandboththeprocesses areonthesamesite.

DataStructures
EachprocessPimaintainsabooleanarray,dependenti,wheredependenti(j)istrueonlyifPiknowsthat
Pjisdependenton it. Initially,dependenti(j) isfalseforalliandj

CARE COLLEGE OF ENGINEERING R.C.Subashini, AP/AI&DS


CS3551 - DISTRIBUTED COMPUTING

Therefore, a probe message is continuously circulated along the edges of the global
WFGgraphand adeadlockisdetectedwhenaprobemessagereturnstoitsinitiatingprocess.

PerformanceAnalysis
Inthealgorithm,oneprobemessage(perdeadlockdetectioninitiation)issentoneveryedgeoftheWF
Gwhichthattwosites.Thus,thealgorithmexchangesatmostm(n−1)/2messagesto detect a
deadlock that involves m processes and that spans over n sites. The size ofmessages is fixed
and is very small (only 3 integer words). Delay in detecting a deadlock isO(n).

CHANDY-MISRA-HAASALGORITHMFORTHEORMODEL

We now discuss Chandy-Misra-Haas distributed deadlock detection algorithm for OR


modelthat is based on the approach of diffusion-computation. A blocked process determines if
it isdeadlockedbyinitiatingadiffusion computation.Twotypesofmessagesareusedinadiffusion
computation: query(i, j, k) and reply(i, j, k), denoting that they belong to a
diffusioncomputationinitiatedbyaprocessPiand arebeingsentfromprocessPjtoprocess Pk.

CARE COLLEGE OF ENGINEERING R.C.Subashini, AP/AI&DS


CS3551 - DISTRIBUTED COMPUTING

BasicIdea

A blocked process initiates deadlock detection by sending query messages to all processes
inits dependent set (i.e., processes from which it is waiting to receive a message). If an
activeprocess receives a query or reply message, it discards it. When a blocked process Pk
receivesaquery(i,j,k)message,ittakesthefollowing actions:

1. If this is the first query message received by Pk for the deadlock detection initiated by
Pi(calledtheengagingquery),thenitpropagatesthequerytoalltheprocessesinitsdependentsetandse
tsalocalvariablenumk(i)tothenumberofquerymessagessent.

2. Ifthisisnottheengagingquery,thenPkreturnsareplymessagetoitimmediatelyprovidedPkhasbee
ncontinuouslyblockedsinceitreceivedthecorrespondingengagingquery.Otherwise,itdiscardsthe
query.ProcessPkmaintainsabooleanvariablewaitk(i)thatdenotesthe fact that it has been
continuously blocked since it received the last engaging query
fromprocessPi.WhenablockedprocessPkreceivesareply(i,j,k)message,itdecrementsnumk(i)onl
y if waitk(i) holds. A process sends a reply message in response to an engaging query
onlyafter it has received a reply to every query message it had sent out for this engaging
query.The initiator process detects a deadlock when it receives reply messages to all the
querymessagesithadsentout.

CARE COLLEGE OF ENGINEERING R.C.Subashini, AP/AI&DS


CS3551 - DISTRIBUTED COMPUTING

For ease of presentation, we assumed that only one diffusion computation is initiated for
aprocess.Inpractice,severaldiffusioncomputationsmaybeinitiatedforaprocess(Adiffusioncomput
ation is initiated every time the process gets blocked), but, at any time only onediffusion
computation is current for any process. However, messages for outdated
diffusioncomputations may still be in transit. The current diffusion computation can be
distinguishedfromoutdatedonesby using sequencenumbers.

PerformanceAnalysis

Foreverydeadlockdetection,thealgorithmexchangesequerymessagesandereplymessages,wheree
=n(n-1)is thenumberofedges.

CARE COLLEGE OF ENGINEERING R.C.Subashini, AP/AI&DS


CS3551 - DISTRIBUTED COMPUTING
Assessment questions to the lecture
Bloom’s
Qn. No. Question Answer Knowledge
Level
Which of the following does the Chandy-Misra-Haas
algorithm primarily detect?
 a) Live locks
1 Option C) K2
 b) Starvation
 c) Deadlocks
 d) Resource allocation
In the AND model, a process can proceed if:
 a) It acquires at least one requested resource.
 b) It acquires all requested resources
2 Option B) K2
simultaneously.
 c) It releases some resources first.
 d) It cancels its request for additional resources.
What is the key mechanism used by the Chandy-Misra-
Haas algorithm to detect deadlocks?
 a) Timeouts
3 Option C) K2
 b) Probe messages
 c) Resource reservation
 d) Priority scheduling
Students have to prepare answers for the following questions at the end of the lecture
Bloom’s
Qn. No Question Marks CO Knowledge
Level
1 Define a deadlock in the context of distributed systems. 2 3 K2
How does the Chandy-Misra-Haas algorithm address it?
2 Explain the role of the Wait-For Graph (WFG) in the 6 3 K1
Chandy-Misra-Haas algorithm. How does it help in
detecting deadlocks in the AND model?
3 Describe the process of sending and receiving probe 13 3 K2
messages in the Chandy-Misra-Haas algorithm. How does
this process contribute to deadlock detection?
4 Discuss in detail the Chandy-Misra-Haas algorithm for the 13 3 K3
AND model. Include the construction of the Wait-For
Graph, the use of probe messages, and the algorithm's
advantages and limitations. Provide an example
illustrating the algorithm's application in a distributed
system.
Reference Book
Author(s) Title of the book Page numbers
Ajay D. Kshemkalyani Distributed Computing Principles, Algorithms
352
and MukeshSinghal and Systems

CARE COLLEGE OF ENGINEERING R.C.Subashini, AP/AI&DS

You might also like