mutual exclusion presented by: rohan sen (distributed algorithms ch. 10)
TRANSCRIPT
![Page 1: Mutual Exclusion Presented by: Rohan Sen (Distributed Algorithms Ch. 10)](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649ed35503460f94be35f1/html5/thumbnails/1.jpg)
Mutual Exclusion
Presented by: Rohan Sen(Distributed Algorithms Ch. 10)
![Page 2: Mutual Exclusion Presented by: Rohan Sen (Distributed Algorithms Ch. 10)](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649ed35503460f94be35f1/html5/thumbnails/2.jpg)
Topics that will be covered
Overview and problem statement
Dijkstra’s Mutual Exclusion Algorithm
Stronger Conditions for Mutual Exclusion Algorithms
Lockout-free Mutual Exclusion Algorithms
Single-Writer Shared Register Algorithms
The Bakery Algorithm
Conclusion
![Page 3: Mutual Exclusion Presented by: Rohan Sen (Distributed Algorithms Ch. 10)](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649ed35503460f94be35f1/html5/thumbnails/3.jpg)
Overview
The shared memory model Every process is a kind of state machine
Set of states Three kinds of actions: input, output, internal
All communication via the shared memory Exists a transition relation for all states
System is input-enabled Not output and internal enabled
Locality restrictions Restrictions on shared variable operations
![Page 4: Mutual Exclusion Presented by: Rohan Sen (Distributed Algorithms Ch. 10)](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649ed35503460f94be35f1/html5/thumbnails/4.jpg)
The problem
Allocation of single, indivisible, non-shareable resource among n users
Steps by a user Trying protocol Critical region Exit protocol Remainder (non-critical
region)
U
try
crit
exit
rem
External interface of a user
![Page 5: Mutual Exclusion Presented by: Rohan Sen (Distributed Algorithms Ch. 10)](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649ed35503460f94be35f1/html5/thumbnails/5.jpg)
The problem (contd.)
A shared memory system solves the mutual exclusion problem when the following conditions are satisfied:Well-formednessMutual exclusionProgress
![Page 6: Mutual Exclusion Presented by: Rohan Sen (Distributed Algorithms Ch. 10)](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649ed35503460f94be35f1/html5/thumbnails/6.jpg)
Dijkstra’s Mutual Exclusion Alg.
ConceptUse a two stage flag to indicate what stage of
processing a user is inEnsure mutual exclusion by ensuring that only
one flag at a time has a value to let it into the critical region
![Page 7: Mutual Exclusion Presented by: Rohan Sen (Distributed Algorithms Ch. 10)](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649ed35503460f94be35f1/html5/thumbnails/7.jpg)
Dijkstra’s Mutual Exclusion Alg.
}2,1,0{)(:1,},......,1{
iflagniieveryfornturn
turn rd / wr by all processes, intially arbitrary flag(i) rd by all / wr by I, initially 0
Shared Variables
![Page 8: Mutual Exclusion Presented by: Rohan Sen (Distributed Algorithms Ch. 10)](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649ed35503460f94be35f1/html5/thumbnails/8.jpg)
Dijkstra’s Mutual Exclusion Alg.
i
i
i
i
remiflag
exit
critLgotothenjflagif
doijforiflag
iturnthenturnflagifdoiturnwhile
iflagLtry
0:)(
........
2)(
2:)(:0)(
1:)(:
![Page 9: Mutual Exclusion Presented by: Rohan Sen (Distributed Algorithms Ch. 10)](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649ed35503460f94be35f1/html5/thumbnails/9.jpg)
Dijkstra’s Mutual Exclusion Alg.
Guarantees well-formednessPer inspection of the code
Satisfies mutual exclusionBy status of flag
Guarantees progressMore complex proof
![Page 10: Mutual Exclusion Presented by: Rohan Sen (Distributed Algorithms Ch. 10)](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649ed35503460f94be35f1/html5/thumbnails/10.jpg)
Stronger Conditions
FairnessNo lockouts or starvationsKinds of fairness
Low level fairness High level fairness
![Page 11: Mutual Exclusion Presented by: Rohan Sen (Distributed Algorithms Ch. 10)](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649ed35503460f94be35f1/html5/thumbnails/11.jpg)
Stronger Conditions (contd.)
Lockout freedom Any user that reaches T eventually enters C Any user that reaches E eventually enters R
Time bound If each user returns resource within time c and each
step is at most l, then you enter C at most b = f(l,c) after entering T
Similarly, you enter R at most b = f(l,c) after entering E.
Number of bypasses
![Page 12: Mutual Exclusion Presented by: Rohan Sen (Distributed Algorithms Ch. 10)](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649ed35503460f94be35f1/html5/thumbnails/12.jpg)
PetersonNP Algorithm
ConceptThere are k levels
At each level eliminate one user n – k processes can win at level k Only one process can win at level n – 1, yielding
mutual exclusion
![Page 13: Mutual Exclusion Presented by: Rohan Sen (Distributed Algorithms Ch. 10)](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649ed35503460f94be35f1/html5/thumbnails/13.jpg)
PetersonNP Algorithm
}1,........,0{)(:1,},.....1{)(
:}1,.......,1{
niflagniieveryfornkturnnkeveryfor
turn(k) rd / wr by all, initially arbitrary flag(i) rd by all j ≠ i / wr by I, initially 0
Shared variables
![Page 14: Mutual Exclusion Presented by: Rohan Sen (Distributed Algorithms Ch. 10)](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649ed35503460f94be35f1/html5/thumbnails/14.jpg)
PetersonNP Algorithm
i
i
i
i
remiflag
exit
critikturnorkjflagijwaitfor
ikturnkiflagdontokfor
try
0:)(
......
])([])(:[:)(:)(
11
![Page 15: Mutual Exclusion Presented by: Rohan Sen (Distributed Algorithms Ch. 10)](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649ed35503460f94be35f1/html5/thumbnails/15.jpg)
PetersonNP Algorithm
Is well formed Satisfies mutual exclusion Guarantees progress Lockout free
![Page 16: Mutual Exclusion Presented by: Rohan Sen (Distributed Algorithms Ch. 10)](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649ed35503460f94be35f1/html5/thumbnails/16.jpg)
Alg. Using Single Writer Shared Registers (BurnsME Algorithm) Concept
Check if anyone else is trying to get a lockLay claim on the lockCheck againProceed
![Page 17: Mutual Exclusion Presented by: Rohan Sen (Distributed Algorithms Ch. 10)](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649ed35503460f94be35f1/html5/thumbnails/17.jpg)
BurnsME Algorithm
}1,0{)(:1,
iflagniieveryfor
Shared variables flag(i) wr by i / rd by all j ≠ I, initially 0
![Page 18: Mutual Exclusion Presented by: Rohan Sen (Distributed Algorithms Ch. 10)](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649ed35503460f94be35f1/html5/thumbnails/18.jpg)
BurnsME Algorithm
i
i
i
i
remiflag
exit
critMgotojflagifdonjijforMLgotojflagif
doijjforiflag
Lgotojflagifdoijjfor
iflagLtry
0:)(
......
1)(1,:
1)(11,
1:)(1)(11,
0:)(:
![Page 19: Mutual Exclusion Presented by: Rohan Sen (Distributed Algorithms Ch. 10)](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649ed35503460f94be35f1/html5/thumbnails/19.jpg)
BurnsME Algorithm
Is well formed Guarantees mutual exclusion Guarantees progress
![Page 20: Mutual Exclusion Presented by: Rohan Sen (Distributed Algorithms Ch. 10)](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649ed35503460f94be35f1/html5/thumbnails/20.jpg)
Bakery Algorithm
ConceptFIFO after a wait-free doorwayDoorway is:
Everyone picks a number Waits for everyone to finish
Break ties and enter critical zone
![Page 21: Mutual Exclusion Presented by: Rohan Sen (Distributed Algorithms Ch. 10)](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649ed35503460f94be35f1/html5/thumbnails/21.jpg)
Bakery Algorithm
)(}1,0{)(:1,
inumberichoosng
niieveryfor
Shared variables
choosng(i) wr by i / rd by all j ≠ I, initially 0
number(i) wr by i / rd by all j ≠ I, initially 0
![Page 22: Mutual Exclusion Presented by: Rohan Sen (Distributed Algorithms Ch. 10)](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649ed35503460f94be35f1/html5/thumbnails/22.jpg)
Bakery Algorithm
i
i
i
j
i
reminumber
exit
critjjnumberiinumberorjberwaitfornum
jchoosngwaitfordoijforichoosng
jnumberinumberichoosng
try
0:)(
......
)),(()),((0)(0)(
0:)()(max1:)(
1:)(1
![Page 23: Mutual Exclusion Presented by: Rohan Sen (Distributed Algorithms Ch. 10)](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649ed35503460f94be35f1/html5/thumbnails/23.jpg)
Bakery Algorithm
Is well formed Satisfies mutual exclusion Guarantees progress Guarantees lockout freedom
![Page 24: Mutual Exclusion Presented by: Rohan Sen (Distributed Algorithms Ch. 10)](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649ed35503460f94be35f1/html5/thumbnails/24.jpg)
Lower bound on # registers
Cannot solve mutual exclusion with <n shared variablesSingle writer shared variablesMulti writer shared variables
![Page 25: Mutual Exclusion Presented by: Rohan Sen (Distributed Algorithms Ch. 10)](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649ed35503460f94be35f1/html5/thumbnails/25.jpg)
Conclusion
Mutual exclusion: One at a time access to a shared resource
Mutual exclusion w/o fairness Mutual exclusion w/ fairness Minimizing the number of registers
![Page 26: Mutual Exclusion Presented by: Rohan Sen (Distributed Algorithms Ch. 10)](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649ed35503460f94be35f1/html5/thumbnails/26.jpg)
Questions?