SlideShare a Scribd company logo
1 of 28
Distributed Mutual Exclusion
Distributed Mutual Exclusion
CS
CS
CS
CS
p0
p1
p2
p3
Distributed Mutual Exclusion
Distributed mutual exclusion Classical mutual exclusion
Why mutual exclusion?
Some applications are:
1. Resource sharing
2. Avoiding concurrent update on shared data
3. Implementing atomic operations
4. Medium Access Control in Ethernet
5. Collision avoidance in wireless broadcasts
Mutual Exclusion Problem
Specifications
ME1. At most one process in the CS. (Safety property)
ME2. No deadlock. (Safety property)
ME3. Every process trying to enter its CS must eventually succeed.
This is called progress. (Liveness property)
Progress is quantified by the criterion of bounded waiting. It measures
a form of fairness by answering the question:
Between two consecutive CS trips by one process, how many times
other processes can enter the CS?
There are many solutions, both on the shared memory model and on the
message-passing model. We first focus on the message-passing model.
Client-server based solution
Using message passing model
CLIENT
repeat
Send request and wait for reply;
Enter CS;
Send release and exit CS
forever
SERVER
repeat request ∧ ¬busy  send reply; busy:= true
[] request ∧ busy  enqueue sender
[] release ∧ queue is empty  busy:= false
[] release ∧ queue not empty  send reply to head of queue
forever
server
client
busy
Comments
- Centralized solution is simple.
- But the central server is a single point of failure. This is BAD.
- ME1-ME3 is satisfied, but FIFO fairness is not guaranteed. Why?
Can we do without a central server? Yes!
Decentralized solution 1
Lamport’s algorithm
1. Broadcast a timestamped request to all.
2. Request received  enqueue it in local Q. Not in CS  send ack,
else postpone sending ack until exit from CS.
3. Enter CS, when
(i) You are at the “head” of your Q
(ii) You have received ack from all
4. To exit from the CS,
(i) Delete the request from your Q, and
(ii) Broadcast a timestamped release
5. When a process receives a release message, it removes the sender
from its Q.
Completely connected topology
Analysis of Lamport’s algorithm
Analysis of Lamport’s algorithm
Proof of ME2. (No deadlock)
The waiting chain is acyclic.
i waits for j ⇒i is behind j in all queues
(or j is already in its CS)
⇒j does not wait for i
Proof of ME3. (progress)
New requests join the end of the queues,
so new requests do not pass the old ones.
Analysis of Lamport’s algorithm
FIFO fairness.
timestamp (j) < timestamp (k) ⇒ j enters its CS before k does so
Does it hold?
FIFO guarantee does not hold.
See the example to the right. Here, k (timestamp 30) enters its CS
before j (timestamp 20). How? Since k did not yet receive j’s request.
But k received the ack from j for its own request . This is possible when
the channel is not FIFO, but impossible if the channels are FIFO.
.
Message complexity = 3(N-1) (per trip to CS)
(N-1 requests + N-1 ack + N-1 release)
k j
Req
(20)
ack
Req (30)
Decentralized algorithm 2
Ricart & Agrawala’s algorithm
What is new?
1. Broadcast a timestamped request to all.
2. Upon receiving a request, send ack if
-You do not want to enter your CS, or
-You are trying to enter your CS, but your timestamp is larger than
that of the sender.
(If you are already in CS or your request has a smaller
timestamp, then buffer the request)
3. Enter CS, when you receive ack from all.
4. Upon exit from CS, send ack to each buffered request
before making a new request.
(No release message is necessary)
ts=10 ts=20
ts=30
ts=27
Ricart & Agrawala’s algorithm
Ricart & Agrawala’s algorithm
ME1. Prove that at most one process can be in CS.
ME2. Prove that deadlock is not possible.
ME3. Prove that FIFO fairness holds even if
channels are not FIFO
Message complexity = 2(N-1)
(N-1 requests + N-1 acks - no release message)
k j
Req(j)
Ack(j)
TS(j) < TS(k)
Req(k)
Unbounded timestamps
Timestamps grow in an unbounded manner.
This makes real implementations impossible.
Can we somehow use bounded timestamps?
Think about it.
Decentralized algorithm 3
{Maekawa’s algorithm}
- First solution with a sublinear O(sqrt N) message
complexity.
- “Close to” Ricart-Agrawala’s solution, but each process
is required to obtain permission from only a subset
of peers
Maekawa’s algorithm
• With each process i, associate a subset
Si. Divide the set of processes into
subsets that satisfy the following two
conditions:
i ∈ Si
∀i,j : 0≤i,j ≤ n-1 | Si ⋂ Sj ≠ ∅
• Main idea. Each process i is required to
receive permission from Si only.
Correctness requires that multiple
processes will never receive permission
from all members of their respective
subsets.
0,1,2 1,3,5
2,4,5
S0
S1
S2
Maekawa’s algorithm
Example. Let there be seven processes 0, 1, 2, 3, 4, 5, 6
S0 = {0, 1, 2}
S1 = {1, 3, 5}
S2 = {2, 4, 5}
S3 = {0, 3, 4}
S4 = {1, 4, 6}
S5 = {0, 5, 6}
S6 = {2, 3, 6}
Maekawa’s algorithm
Version 1 {Life of process I}
1. Send timestamped request to each process in Si.
2. Request received  send ack to process with the
lowest timestamp. Thereafter, "lock" (i.e. commit)
yourself to that process, and keep others waiting.
3. Enter CS if you receive an ack from each member
in Si.
4. To exit CS, send release to every process in Si.
5. Release received  unlock yourself. Then send
ack to the next process with the lowest timestamp.
S0= {0, 1, 2}
S1= {1, 3, 5}
S2= {2, 4, 5}
S3= {0, 3, 4}
S4= {1, 4, 6}
S5= {0, 5, 6}
S6= {2, 3, 6}
Maekawa’s algorithm-version 1
ME1. At most one process can enter its critical
section at any time.
Let i and j attempt to enter their Critical Sections
Si ∩ Sj ≠ ∅ implies there is a process k ∊ Si ⋂ Sj
Process k will never send ack to both.
So it will act as the arbitrator and establishes ME1
S0= {0, 1, 2}
S1= {1, 3, 5}
S2= {2, 4, 5}
S3= {0, 3, 4}
S4= {1, 4, 6}
S5= {0, 5, 6}
S6= {2, 3, 6}
Maekawa’s algorithm-version 1
ME2. No deadlock. Unfortunately deadlock is
possible! Assume 0, 1, 2 want to enter their
critical sections.
From S0= {0,1,2}, 0,2 send ack to 0, but 1 sends ack to 1;
From S1= {1,3,5}, 1,3 send ack to 1, but 5 sends ack to 2;
From S2= {2,4,5}, 4,5 send ack to 2, but 2 sends ack to 0;
Now, 0 waits for 1 (to send a release), 1 waits for 2 (to send a
release), , and 2 waits for 0 (to send a release), . So deadlock
is possible!
S0= {0, 1, 2}
S1= {1, 3, 5}
S2= {2, 4, 5}
S3= {0, 3, 4}
S4= {1, 4, 6}
S5= {0, 5, 6}
S6= {2, 3, 6}
Maekawa’s algorithm-Version 2
Avoiding deadlock
If processes always receive messages in
increasing order of timestamp, then
deadlock “could be” avoided. But this is too
strong an assumption.
Version 2 uses three additional messages:
- failed
- inquire
- relinquish
S0= {0, 1, 2}
S1= {1, 3, 5}
S2= {2, 4, 5}
S3= {0, 3, 4}
S4= {1, 4, 6}
S5= {0, 5, 6}
S6= {2, 3, 6}
Maekawa’s algorithm-Version 2
New features in version 2
- Send ack and set lock as usual.
- If lock is set and a request with a larger
timestamp arrives, send failed (you have no
chance). If the incoming request has a lower
timestamp, then send inquire (are you in CS?)
to the locked process.
- Receive inquire and at least one failed
message  send relinquish. The recipient
resets the lock.
S0 = {0, 1, 2}
S1 = {1, 3, 5}
S2 = {2, 4, 5}
S3 = {0, 3, 4}
S4 = {1, 4, 6}
S5 = {0, 5, 6}
S6 = {2, 3, 6}
Maekawa’s algorithm-Version 2
Comments
- Let K = |Si|. Let each process be a member of D
subsets. When N = 7, K = D = 3. When K=D, N
= K(K-1)+1. So K =O(√N)
- The message complexity of Version 1 is 3√N.
Maekawa’s analysis of Version 2 reveals a
complexity of 7√N
• Sanders identified a bug in version 2 …
Token-passing Algorithms for mutual
exclusion
Suzuki-Kasami algorithm
For a completely connected network of processes
The Main idea
There is one token in the network. The holder of the token
has the permission to enter CS.
Any other process trying to enter CS must acquire that
token. Thus the token will move from one process to
another based on demand.
I want to enter CS
I want to enter CS
(See the textbook for details)
Mutual Exclusion in Shared Memory Model
M
0 2
1 N
{program for process 0}
do true →
flag[0] = true;
do flag[1] → skip od
critical section;
flag[0] = false;
non-critical section codes;
od
{program for process 1}
do true →
flag[1] = true;
do flag[0] → skip od;
critical section;
flag[1] = false;
non-critical section codes;
od
program peterson;
define flag[0], flag[1] : shared boolean;
initially flag[0] = false, flag[1] = false
First attempt
Does it work?
{program for process 0}
do true →
flag[0] = true;
turn = 0;
do (flag[1] ⋀ turn =0) → skip od
critical section;
flag[0] = false;
non-critical section codes;
od
{program for process 1}
do true →
flag[1] = true;
turn = 1;
do (flag[0] ⋀ turn = 1) → skip od;
critical section;
flag[1] = false;
non-critical section codes;
od
program peterson;
define flag[0], flag[1] : shared boolean;
turn: shared integer
initially flag[0] = false, flag[1] = false, turn = 0 or 1
Petersen’s algorithm
Simplest 2-process
mutex algorithm

More Related Content

Similar to mutual exclusion algos 16619.4 pptx cloud computing

Algorithm analysis.pptx
Algorithm analysis.pptxAlgorithm analysis.pptx
Algorithm analysis.pptxDrBashirMSaad
 
Distributed System by Pratik Tambekar
Distributed System by Pratik TambekarDistributed System by Pratik Tambekar
Distributed System by Pratik TambekarPratik Tambekar
 
Mutual Exclusion using Peterson's Algorithm
Mutual Exclusion using Peterson's AlgorithmMutual Exclusion using Peterson's Algorithm
Mutual Exclusion using Peterson's AlgorithmSouvik Roy
 
DC Lecture 04 and 05 Mutual Excution and Election Algorithms.pdf
DC Lecture 04 and 05 Mutual Excution and Election Algorithms.pdfDC Lecture 04 and 05 Mutual Excution and Election Algorithms.pdf
DC Lecture 04 and 05 Mutual Excution and Election Algorithms.pdfLegesseSamuel
 
Datastage real time scenario
Datastage real time scenarioDatastage real time scenario
Datastage real time scenarioNaresh Bala
 
Tugas komjar 7-yee
Tugas komjar 7-yeeTugas komjar 7-yee
Tugas komjar 7-yeeramasatriaf
 
Distributed system TimeNState-Tanenbaum.ppt
Distributed system TimeNState-Tanenbaum.pptDistributed system TimeNState-Tanenbaum.ppt
Distributed system TimeNState-Tanenbaum.pptTantraNathjha1
 
Operating system 24 mutex locks and semaphores
Operating system 24 mutex locks and semaphoresOperating system 24 mutex locks and semaphores
Operating system 24 mutex locks and semaphoresVaibhav Khanna
 
Distributed Computing On Topics of: Leader election + Byzantine algorithms)
Distributed Computing On Topics of: Leader election + Byzantine algorithms)Distributed Computing On Topics of: Leader election + Byzantine algorithms)
Distributed Computing On Topics of: Leader election + Byzantine algorithms)Osama Askoura
 
Lecture 3 insertion sort and complexity analysis
Lecture 3   insertion sort and complexity analysisLecture 3   insertion sort and complexity analysis
Lecture 3 insertion sort and complexity analysisjayavignesh86
 
Parallel sorting algorithm
Parallel sorting algorithmParallel sorting algorithm
Parallel sorting algorithmRicha Kumari
 
IEC 60870-5 101 Protocol Server Simulator User manual
IEC 60870-5 101 Protocol Server Simulator User manualIEC 60870-5 101 Protocol Server Simulator User manual
IEC 60870-5 101 Protocol Server Simulator User manualFreyrSCADA Embedded Solution
 

Similar to mutual exclusion algos 16619.4 pptx cloud computing (20)

Distributed System
Distributed SystemDistributed System
Distributed System
 
Algorithm analysis.pptx
Algorithm analysis.pptxAlgorithm analysis.pptx
Algorithm analysis.pptx
 
Distributed System by Pratik Tambekar
Distributed System by Pratik TambekarDistributed System by Pratik Tambekar
Distributed System by Pratik Tambekar
 
Mutual Exclusion using Peterson's Algorithm
Mutual Exclusion using Peterson's AlgorithmMutual Exclusion using Peterson's Algorithm
Mutual Exclusion using Peterson's Algorithm
 
DC Lecture 04 and 05 Mutual Excution and Election Algorithms.pdf
DC Lecture 04 and 05 Mutual Excution and Election Algorithms.pdfDC Lecture 04 and 05 Mutual Excution and Election Algorithms.pdf
DC Lecture 04 and 05 Mutual Excution and Election Algorithms.pdf
 
Datastage real time scenario
Datastage real time scenarioDatastage real time scenario
Datastage real time scenario
 
TCP timers.ppt
TCP timers.pptTCP timers.ppt
TCP timers.ppt
 
persist timer.ppt
persist timer.pptpersist timer.ppt
persist timer.ppt
 
Tugas komjar 7-yee
Tugas komjar 7-yeeTugas komjar 7-yee
Tugas komjar 7-yee
 
Distributed system TimeNState-Tanenbaum.ppt
Distributed system TimeNState-Tanenbaum.pptDistributed system TimeNState-Tanenbaum.ppt
Distributed system TimeNState-Tanenbaum.ppt
 
Cgc2
Cgc2Cgc2
Cgc2
 
Operating system 24 mutex locks and semaphores
Operating system 24 mutex locks and semaphoresOperating system 24 mutex locks and semaphores
Operating system 24 mutex locks and semaphores
 
CH05.pdf
CH05.pdfCH05.pdf
CH05.pdf
 
wireless proj 2
wireless proj 2wireless proj 2
wireless proj 2
 
Deadlock
DeadlockDeadlock
Deadlock
 
Distributed Computing On Topics of: Leader election + Byzantine algorithms)
Distributed Computing On Topics of: Leader election + Byzantine algorithms)Distributed Computing On Topics of: Leader election + Byzantine algorithms)
Distributed Computing On Topics of: Leader election + Byzantine algorithms)
 
Isola 12 presentation
Isola 12 presentationIsola 12 presentation
Isola 12 presentation
 
Lecture 3 insertion sort and complexity analysis
Lecture 3   insertion sort and complexity analysisLecture 3   insertion sort and complexity analysis
Lecture 3 insertion sort and complexity analysis
 
Parallel sorting algorithm
Parallel sorting algorithmParallel sorting algorithm
Parallel sorting algorithm
 
IEC 60870-5 101 Protocol Server Simulator User manual
IEC 60870-5 101 Protocol Server Simulator User manualIEC 60870-5 101 Protocol Server Simulator User manual
IEC 60870-5 101 Protocol Server Simulator User manual
 

Recently uploaded

5G and 6G refer to generations of mobile network technology, each representin...
5G and 6G refer to generations of mobile network technology, each representin...5G and 6G refer to generations of mobile network technology, each representin...
5G and 6G refer to generations of mobile network technology, each representin...archanaece3
 
Diploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdfDiploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdfJNTUA
 
Lab Manual Arduino UNO Microcontrollar.docx
Lab Manual Arduino UNO Microcontrollar.docxLab Manual Arduino UNO Microcontrollar.docx
Lab Manual Arduino UNO Microcontrollar.docxRashidFaridChishti
 
The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...
The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...
The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...Roi Lipman
 
Intelligent Agents, A discovery on How A Rational Agent Acts
Intelligent Agents, A discovery on How A Rational Agent ActsIntelligent Agents, A discovery on How A Rational Agent Acts
Intelligent Agents, A discovery on How A Rational Agent ActsSheetal Jain
 
Introduction to Arduino Programming: Features of Arduino
Introduction to Arduino Programming: Features of ArduinoIntroduction to Arduino Programming: Features of Arduino
Introduction to Arduino Programming: Features of ArduinoAbhimanyu Sangale
 
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdfInvolute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdfJNTUA
 
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas SachpazisSeismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas SachpazisDr.Costas Sachpazis
 
Fabrication Of Automatic Star Delta Starter Using Relay And GSM Module By Utk...
Fabrication Of Automatic Star Delta Starter Using Relay And GSM Module By Utk...Fabrication Of Automatic Star Delta Starter Using Relay And GSM Module By Utk...
Fabrication Of Automatic Star Delta Starter Using Relay And GSM Module By Utk...ShivamTiwari995432
 
Artificial Intelligence Bayesian Reasoning
Artificial Intelligence Bayesian ReasoningArtificial Intelligence Bayesian Reasoning
Artificial Intelligence Bayesian Reasoninghotman30312
 
Operating System chapter 9 (Virtual Memory)
Operating System chapter 9 (Virtual Memory)Operating System chapter 9 (Virtual Memory)
Operating System chapter 9 (Virtual Memory)NareenAsad
 
Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...
Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...
Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...drjose256
 
Quiz application system project report..pdf
Quiz application system project report..pdfQuiz application system project report..pdf
Quiz application system project report..pdfKamal Acharya
 
analog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptxanalog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptxKarpagam Institute of Teechnology
 
Piping and instrumentation diagram p.pdf
Piping and instrumentation diagram p.pdfPiping and instrumentation diagram p.pdf
Piping and instrumentation diagram p.pdfAshrafRagab14
 
Module-III Varried Flow.pptx GVF Definition, Water Surface Profile Dynamic Eq...
Module-III Varried Flow.pptx GVF Definition, Water Surface Profile Dynamic Eq...Module-III Varried Flow.pptx GVF Definition, Water Surface Profile Dynamic Eq...
Module-III Varried Flow.pptx GVF Definition, Water Surface Profile Dynamic Eq...Nitin Sonavane
 
Multivibrator and its types defination and usges.pptx
Multivibrator and its types defination and usges.pptxMultivibrator and its types defination and usges.pptx
Multivibrator and its types defination and usges.pptxalijaker017
 
Final DBMS Manual (2).pdf final lab manual
Final DBMS Manual (2).pdf final lab manualFinal DBMS Manual (2).pdf final lab manual
Final DBMS Manual (2).pdf final lab manualBalamuruganV28
 
Filters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility ApplicationsFilters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility ApplicationsMathias Magdowski
 
BORESCOPE INSPECTION for engins CFM56.pdf
BORESCOPE INSPECTION for engins CFM56.pdfBORESCOPE INSPECTION for engins CFM56.pdf
BORESCOPE INSPECTION for engins CFM56.pdfomarzaboub1997
 

Recently uploaded (20)

5G and 6G refer to generations of mobile network technology, each representin...
5G and 6G refer to generations of mobile network technology, each representin...5G and 6G refer to generations of mobile network technology, each representin...
5G and 6G refer to generations of mobile network technology, each representin...
 
Diploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdfDiploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdf
 
Lab Manual Arduino UNO Microcontrollar.docx
Lab Manual Arduino UNO Microcontrollar.docxLab Manual Arduino UNO Microcontrollar.docx
Lab Manual Arduino UNO Microcontrollar.docx
 
The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...
The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...
The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...
 
Intelligent Agents, A discovery on How A Rational Agent Acts
Intelligent Agents, A discovery on How A Rational Agent ActsIntelligent Agents, A discovery on How A Rational Agent Acts
Intelligent Agents, A discovery on How A Rational Agent Acts
 
Introduction to Arduino Programming: Features of Arduino
Introduction to Arduino Programming: Features of ArduinoIntroduction to Arduino Programming: Features of Arduino
Introduction to Arduino Programming: Features of Arduino
 
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdfInvolute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
 
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas SachpazisSeismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
 
Fabrication Of Automatic Star Delta Starter Using Relay And GSM Module By Utk...
Fabrication Of Automatic Star Delta Starter Using Relay And GSM Module By Utk...Fabrication Of Automatic Star Delta Starter Using Relay And GSM Module By Utk...
Fabrication Of Automatic Star Delta Starter Using Relay And GSM Module By Utk...
 
Artificial Intelligence Bayesian Reasoning
Artificial Intelligence Bayesian ReasoningArtificial Intelligence Bayesian Reasoning
Artificial Intelligence Bayesian Reasoning
 
Operating System chapter 9 (Virtual Memory)
Operating System chapter 9 (Virtual Memory)Operating System chapter 9 (Virtual Memory)
Operating System chapter 9 (Virtual Memory)
 
Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...
Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...
Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...
 
Quiz application system project report..pdf
Quiz application system project report..pdfQuiz application system project report..pdf
Quiz application system project report..pdf
 
analog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptxanalog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptx
 
Piping and instrumentation diagram p.pdf
Piping and instrumentation diagram p.pdfPiping and instrumentation diagram p.pdf
Piping and instrumentation diagram p.pdf
 
Module-III Varried Flow.pptx GVF Definition, Water Surface Profile Dynamic Eq...
Module-III Varried Flow.pptx GVF Definition, Water Surface Profile Dynamic Eq...Module-III Varried Flow.pptx GVF Definition, Water Surface Profile Dynamic Eq...
Module-III Varried Flow.pptx GVF Definition, Water Surface Profile Dynamic Eq...
 
Multivibrator and its types defination and usges.pptx
Multivibrator and its types defination and usges.pptxMultivibrator and its types defination and usges.pptx
Multivibrator and its types defination and usges.pptx
 
Final DBMS Manual (2).pdf final lab manual
Final DBMS Manual (2).pdf final lab manualFinal DBMS Manual (2).pdf final lab manual
Final DBMS Manual (2).pdf final lab manual
 
Filters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility ApplicationsFilters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility Applications
 
BORESCOPE INSPECTION for engins CFM56.pdf
BORESCOPE INSPECTION for engins CFM56.pdfBORESCOPE INSPECTION for engins CFM56.pdf
BORESCOPE INSPECTION for engins CFM56.pdf
 

mutual exclusion algos 16619.4 pptx cloud computing

  • 3. Distributed Mutual Exclusion Distributed mutual exclusion Classical mutual exclusion
  • 4. Why mutual exclusion? Some applications are: 1. Resource sharing 2. Avoiding concurrent update on shared data 3. Implementing atomic operations 4. Medium Access Control in Ethernet 5. Collision avoidance in wireless broadcasts
  • 5. Mutual Exclusion Problem Specifications ME1. At most one process in the CS. (Safety property) ME2. No deadlock. (Safety property) ME3. Every process trying to enter its CS must eventually succeed. This is called progress. (Liveness property) Progress is quantified by the criterion of bounded waiting. It measures a form of fairness by answering the question: Between two consecutive CS trips by one process, how many times other processes can enter the CS? There are many solutions, both on the shared memory model and on the message-passing model. We first focus on the message-passing model.
  • 6. Client-server based solution Using message passing model CLIENT repeat Send request and wait for reply; Enter CS; Send release and exit CS forever SERVER repeat request ∧ ¬busy  send reply; busy:= true [] request ∧ busy  enqueue sender [] release ∧ queue is empty  busy:= false [] release ∧ queue not empty  send reply to head of queue forever server client busy
  • 7. Comments - Centralized solution is simple. - But the central server is a single point of failure. This is BAD. - ME1-ME3 is satisfied, but FIFO fairness is not guaranteed. Why? Can we do without a central server? Yes!
  • 8. Decentralized solution 1 Lamport’s algorithm 1. Broadcast a timestamped request to all. 2. Request received  enqueue it in local Q. Not in CS  send ack, else postpone sending ack until exit from CS. 3. Enter CS, when (i) You are at the “head” of your Q (ii) You have received ack from all 4. To exit from the CS, (i) Delete the request from your Q, and (ii) Broadcast a timestamped release 5. When a process receives a release message, it removes the sender from its Q. Completely connected topology
  • 10. Analysis of Lamport’s algorithm Proof of ME2. (No deadlock) The waiting chain is acyclic. i waits for j ⇒i is behind j in all queues (or j is already in its CS) ⇒j does not wait for i Proof of ME3. (progress) New requests join the end of the queues, so new requests do not pass the old ones.
  • 11. Analysis of Lamport’s algorithm FIFO fairness. timestamp (j) < timestamp (k) ⇒ j enters its CS before k does so Does it hold? FIFO guarantee does not hold. See the example to the right. Here, k (timestamp 30) enters its CS before j (timestamp 20). How? Since k did not yet receive j’s request. But k received the ack from j for its own request . This is possible when the channel is not FIFO, but impossible if the channels are FIFO. . Message complexity = 3(N-1) (per trip to CS) (N-1 requests + N-1 ack + N-1 release) k j Req (20) ack Req (30)
  • 12. Decentralized algorithm 2 Ricart & Agrawala’s algorithm What is new? 1. Broadcast a timestamped request to all. 2. Upon receiving a request, send ack if -You do not want to enter your CS, or -You are trying to enter your CS, but your timestamp is larger than that of the sender. (If you are already in CS or your request has a smaller timestamp, then buffer the request) 3. Enter CS, when you receive ack from all. 4. Upon exit from CS, send ack to each buffered request before making a new request. (No release message is necessary) ts=10 ts=20 ts=30 ts=27
  • 13. Ricart & Agrawala’s algorithm Ricart & Agrawala’s algorithm ME1. Prove that at most one process can be in CS. ME2. Prove that deadlock is not possible. ME3. Prove that FIFO fairness holds even if channels are not FIFO Message complexity = 2(N-1) (N-1 requests + N-1 acks - no release message) k j Req(j) Ack(j) TS(j) < TS(k) Req(k)
  • 14. Unbounded timestamps Timestamps grow in an unbounded manner. This makes real implementations impossible. Can we somehow use bounded timestamps? Think about it.
  • 15. Decentralized algorithm 3 {Maekawa’s algorithm} - First solution with a sublinear O(sqrt N) message complexity. - “Close to” Ricart-Agrawala’s solution, but each process is required to obtain permission from only a subset of peers
  • 16. Maekawa’s algorithm • With each process i, associate a subset Si. Divide the set of processes into subsets that satisfy the following two conditions: i ∈ Si ∀i,j : 0≤i,j ≤ n-1 | Si ⋂ Sj ≠ ∅ • Main idea. Each process i is required to receive permission from Si only. Correctness requires that multiple processes will never receive permission from all members of their respective subsets. 0,1,2 1,3,5 2,4,5 S0 S1 S2
  • 17. Maekawa’s algorithm Example. Let there be seven processes 0, 1, 2, 3, 4, 5, 6 S0 = {0, 1, 2} S1 = {1, 3, 5} S2 = {2, 4, 5} S3 = {0, 3, 4} S4 = {1, 4, 6} S5 = {0, 5, 6} S6 = {2, 3, 6}
  • 18. Maekawa’s algorithm Version 1 {Life of process I} 1. Send timestamped request to each process in Si. 2. Request received  send ack to process with the lowest timestamp. Thereafter, "lock" (i.e. commit) yourself to that process, and keep others waiting. 3. Enter CS if you receive an ack from each member in Si. 4. To exit CS, send release to every process in Si. 5. Release received  unlock yourself. Then send ack to the next process with the lowest timestamp. S0= {0, 1, 2} S1= {1, 3, 5} S2= {2, 4, 5} S3= {0, 3, 4} S4= {1, 4, 6} S5= {0, 5, 6} S6= {2, 3, 6}
  • 19. Maekawa’s algorithm-version 1 ME1. At most one process can enter its critical section at any time. Let i and j attempt to enter their Critical Sections Si ∩ Sj ≠ ∅ implies there is a process k ∊ Si ⋂ Sj Process k will never send ack to both. So it will act as the arbitrator and establishes ME1 S0= {0, 1, 2} S1= {1, 3, 5} S2= {2, 4, 5} S3= {0, 3, 4} S4= {1, 4, 6} S5= {0, 5, 6} S6= {2, 3, 6}
  • 20. Maekawa’s algorithm-version 1 ME2. No deadlock. Unfortunately deadlock is possible! Assume 0, 1, 2 want to enter their critical sections. From S0= {0,1,2}, 0,2 send ack to 0, but 1 sends ack to 1; From S1= {1,3,5}, 1,3 send ack to 1, but 5 sends ack to 2; From S2= {2,4,5}, 4,5 send ack to 2, but 2 sends ack to 0; Now, 0 waits for 1 (to send a release), 1 waits for 2 (to send a release), , and 2 waits for 0 (to send a release), . So deadlock is possible! S0= {0, 1, 2} S1= {1, 3, 5} S2= {2, 4, 5} S3= {0, 3, 4} S4= {1, 4, 6} S5= {0, 5, 6} S6= {2, 3, 6}
  • 21. Maekawa’s algorithm-Version 2 Avoiding deadlock If processes always receive messages in increasing order of timestamp, then deadlock “could be” avoided. But this is too strong an assumption. Version 2 uses three additional messages: - failed - inquire - relinquish S0= {0, 1, 2} S1= {1, 3, 5} S2= {2, 4, 5} S3= {0, 3, 4} S4= {1, 4, 6} S5= {0, 5, 6} S6= {2, 3, 6}
  • 22. Maekawa’s algorithm-Version 2 New features in version 2 - Send ack and set lock as usual. - If lock is set and a request with a larger timestamp arrives, send failed (you have no chance). If the incoming request has a lower timestamp, then send inquire (are you in CS?) to the locked process. - Receive inquire and at least one failed message  send relinquish. The recipient resets the lock. S0 = {0, 1, 2} S1 = {1, 3, 5} S2 = {2, 4, 5} S3 = {0, 3, 4} S4 = {1, 4, 6} S5 = {0, 5, 6} S6 = {2, 3, 6}
  • 24. Comments - Let K = |Si|. Let each process be a member of D subsets. When N = 7, K = D = 3. When K=D, N = K(K-1)+1. So K =O(√N) - The message complexity of Version 1 is 3√N. Maekawa’s analysis of Version 2 reveals a complexity of 7√N • Sanders identified a bug in version 2 …
  • 25. Token-passing Algorithms for mutual exclusion Suzuki-Kasami algorithm For a completely connected network of processes The Main idea There is one token in the network. The holder of the token has the permission to enter CS. Any other process trying to enter CS must acquire that token. Thus the token will move from one process to another based on demand. I want to enter CS I want to enter CS (See the textbook for details)
  • 26. Mutual Exclusion in Shared Memory Model M 0 2 1 N
  • 27. {program for process 0} do true → flag[0] = true; do flag[1] → skip od critical section; flag[0] = false; non-critical section codes; od {program for process 1} do true → flag[1] = true; do flag[0] → skip od; critical section; flag[1] = false; non-critical section codes; od program peterson; define flag[0], flag[1] : shared boolean; initially flag[0] = false, flag[1] = false First attempt Does it work?
  • 28. {program for process 0} do true → flag[0] = true; turn = 0; do (flag[1] ⋀ turn =0) → skip od critical section; flag[0] = false; non-critical section codes; od {program for process 1} do true → flag[1] = true; turn = 1; do (flag[0] ⋀ turn = 1) → skip od; critical section; flag[1] = false; non-critical section codes; od program peterson; define flag[0], flag[1] : shared boolean; turn: shared integer initially flag[0] = false, flag[1] = false, turn = 0 or 1 Petersen’s algorithm Simplest 2-process mutex algorithm