SlideShare a Scribd company logo
1 of 37
Plan for Today
Dijkstra’s Mutual Exclusion Solution
Lamport’s Solution
Dining Philosophers
1
Reminder: Everyone should
have scheduled a project
progress meeting!
Project Update
Every team should have a progress/review meeting scheduled
– Discuss what you have done so far and plans to finish
Project submission:
– Web form (including link to github repo or other web content):
accepted without penalty until Monday, 5 May (11:59pm)
– Option of either:
In-class presentation/demo (April 24 or April 29)
Formal written report (due April 29, 11:59pm)
Something else
2
No final exam, unless your project is embarrassing. Then
you’ll have a chance to make up for it by doing a final exam.
You have until Monday
(Apr 21) to submit a form
with your preferences,
but priority will be given
to earlier submissions!
Why so much on mutual exclusion?
3
4
5
6
Program for Processor i
loop {
b[i] := false
L1: if k != i
c[i] := true
if b[k]:
k := i
goto L1
else:
c[i] := false;
L4: for j in [1, …, N]:
if j != i and not c[j]:
goto L1
critical section;
c[i] := true
b[i] := true
}
How do we know none of the c[.]’s
changed during the loop?
Where we got last class:
7
Program for Processor i
loop {
1: b[i] := false
2: if k != i:
3: c[i] := true
4: if b[k]:
5: k := i
6: goto L2
else:
7: c[i] := false;
8: for j in [1, …, N]:
9: if j != i and not c[j]:
10: goto L2
11: critical section;
12: c[i] := true
13: b[i] := true
}
How do we know none of the c[.]’s
changed during the loop?
8
Program for Processor i
loop {
b[i] := false
L1: if k != i
c[i] := true
if b[k]:
k := i
goto L1
else:
c[i] := false;
L4: for j in [1, …, N]:
if j != i and not c[j]:
goto L1
critical section;
c[i] := true
b[i] := true
}
9
Liveness ProofProgram for Processor i
loop {
b[i] := false
L1: if k != i
c[i] := true
L3: if b[k]:
k := i
goto L1
else:
c[i] := false;
L4: for j in [1, …, N]:
if j != i and not c[j]:
goto L1
critical section;
c[i] := true
b[i] := true
}
10
Assumptions?
Program for Processor i
loop {
b[i] := false
L1: if k != i
c[i] := true
L3: if b[k]:
k := i
goto L1
else:
c[i] := false;
L4: for j in [1, …, N]:
if j != i and not c[j]:
goto L1
critical section;
c[i] := true
b[i] := true
}
11
“When I was at Compass, I read a
paper in Communications of the
ACM about a mutual-exclusion
algorithm,” Lamport recalls. “It
was the first time I had seen the
mutual-exclusion problem, and I
looked at it and said, ‘Well, that
doesn’t seem very difficult.’”
12
“What is significant about the bakery algorithm
is that it implements mutual exclusion without
relying on any lower-level mutual exclusion.
Assuming that reads and writes of a memory
location are atomic actions, as previous mutual
exclusion algorithms had done, is tantamount
to assuming mutually exclusive access to the
location. So a mutual exclusion algorithm that
assumes atomic reads and writes is assuming
lower-level mutual exclusion. Such an
algorithm cannot really be said to solve the
mutual exclusion problem. Before the bakery
algorithm, people believed that the mutual
exclusion problem was unsolvable--that you
could implement mutual exclusion only by
using lower-level mutual exclusion.”Communications of the ACM,
August 1974 (2 pages)
13
14
15
T2 T3 T4T1
N independent threads
Shared Memory (no exclusion!)
T5 Program:
loop {
non-critical {
…
}
critical {
…
}
}
Requirements:
1. Only one thread may be in the critical section at any time.
2. Each must eventually be able to enter its critical section.
3. Must be symmetrical (all run same program).
4. Cannot make any assumptions about speed of threads.
5. Only writes are guaranteed (when simultaneous).
16
Processor number: i
17
If the write changes the value
from 0 to 1, a concurrent read
could obtain the value 7456
(assuming that 7456 is a value
that could be in the memory
location). The algorithm still
works. I didn't try to devise an
algorithm with this property. I
discovered that the bakery
algorithm had this property after
writing a proof of its correctness
and noticing that the proof did
not depend on what value is
returned by a read that overlaps
a write.
18
19
20
21
How could number[i] = number[k]?
22
23
24
25
26Sir Tony Hoare (born 1934)
27
28
Heraclitus
Socrates
Plato
Aristotle
Euclid
29
5 Dining Philosophers
5 Chopsticks (one between each pair)
Need 2 chopsticks to eat
30
Could all the
philosophers starve?
31
No (extra) communication
No deadlock
No starvation
Fair
Djikstra’s (Hygenic) Version EWD625
32
Is this equivalent to the shared chopsticks?
Solution Desiderata
No communication required
No deadlock
No starvation: everyone gets to eat eventually
Fair: each philosopher has equal likelihood of
getting to eat
33
Dijkstra’s Solution (Idea)
Number the chopsticks
Always grab lower-numbered stick
first
34
Does it matter how the chopsticks are numbered?
The Real Idea was to
“Invent the Chopstick”
Binary Semaphore
Lock that can be held
by up to one process
35
http://commons.wikimedia.org/wiki/File:Chopstick.png
Charge
36
Many more interesting problems and solutions in
distributed algorithms:
Consensus
Leader election
Reliable broadcast
…
Next class:
Microkernels, Exokernels, and “Zepto”-kernels
Hardware solutions only help
when all threads are running
on the same processor

More Related Content

What's hot

Μεταπρογραµµατισµός κώδικα Python σε γλώσσα γραµµικού χρόνου για αυτόµατη επα...
Μεταπρογραµµατισµός κώδικα Python σε γλώσσα γραµµικού χρόνου για αυτόµατη επα...Μεταπρογραµµατισµός κώδικα Python σε γλώσσα γραµµικού χρόνου για αυτόµατη επα...
Μεταπρογραµµατισµός κώδικα Python σε γλώσσα γραµµικού χρόνου για αυτόµατη επα...
ISSEL
 
Fast dynamic analysis, Kostya Serebryany
Fast dynamic analysis, Kostya SerebryanyFast dynamic analysis, Kostya Serebryany
Fast dynamic analysis, Kostya Serebryany
yaevents
 

What's hot (20)

Modelling Machine Type Communication in IEEE 802.11ah Networks
Modelling Machine Type Communicationin IEEE 802.11ah NetworksModelling Machine Type Communicationin IEEE 802.11ah Networks
Modelling Machine Type Communication in IEEE 802.11ah Networks
 
Μεταπρογραµµατισµός κώδικα Python σε γλώσσα γραµµικού χρόνου για αυτόµατη επα...
Μεταπρογραµµατισµός κώδικα Python σε γλώσσα γραµµικού χρόνου για αυτόµατη επα...Μεταπρογραµµατισµός κώδικα Python σε γλώσσα γραµµικού χρόνου για αυτόµατη επα...
Μεταπρογραµµατισµός κώδικα Python σε γλώσσα γραµµικού χρόνου για αυτόµατη επα...
 
Coroutines in Kotlin
Coroutines in KotlinCoroutines in Kotlin
Coroutines in Kotlin
 
Parametrized Model Checking of Fault Tolerant Distributed Algorithms by Abstr...
Parametrized Model Checking of Fault Tolerant Distributed Algorithms by Abstr...Parametrized Model Checking of Fault Tolerant Distributed Algorithms by Abstr...
Parametrized Model Checking of Fault Tolerant Distributed Algorithms by Abstr...
 
Cryptographic algorithms
Cryptographic algorithmsCryptographic algorithms
Cryptographic algorithms
 
Secured algorithm for gsm encryption & decryption
Secured algorithm for gsm encryption & decryptionSecured algorithm for gsm encryption & decryption
Secured algorithm for gsm encryption & decryption
 
Operating System Engineering
Operating System EngineeringOperating System Engineering
Operating System Engineering
 
NTUT Information Security Homework 1
NTUT Information Security Homework 1 NTUT Information Security Homework 1
NTUT Information Security Homework 1
 
Schizophrenic files v2
Schizophrenic files v2Schizophrenic files v2
Schizophrenic files v2
 
A closure ekon16
A closure ekon16A closure ekon16
A closure ekon16
 
Python multithreading
Python multithreadingPython multithreading
Python multithreading
 
Python multithreading
Python multithreadingPython multithreading
Python multithreading
 
Machine Learning on Code - SF meetup
Machine Learning on Code - SF meetupMachine Learning on Code - SF meetup
Machine Learning on Code - SF meetup
 
The Effect of Hierarchical Memory on the Design of Parallel Algorithms and th...
The Effect of Hierarchical Memory on the Design of Parallel Algorithms and th...The Effect of Hierarchical Memory on the Design of Parallel Algorithms and th...
The Effect of Hierarchical Memory on the Design of Parallel Algorithms and th...
 
Attackboard slides dac12-0605
Attackboard slides dac12-0605Attackboard slides dac12-0605
Attackboard slides dac12-0605
 
Fast dynamic analysis, Kostya Serebryany
Fast dynamic analysis, Kostya SerebryanyFast dynamic analysis, Kostya Serebryany
Fast dynamic analysis, Kostya Serebryany
 
18103010 algorithm complexity (iterative)
18103010 algorithm complexity (iterative)18103010 algorithm complexity (iterative)
18103010 algorithm complexity (iterative)
 
CRYPTANALYSIS AGAINST SYMMETRICKEY SCHEMES WITH ONLINE CLASSICAL QUERIES AND ...
CRYPTANALYSIS AGAINST SYMMETRICKEY SCHEMES WITH ONLINE CLASSICAL QUERIES AND ...CRYPTANALYSIS AGAINST SYMMETRICKEY SCHEMES WITH ONLINE CLASSICAL QUERIES AND ...
CRYPTANALYSIS AGAINST SYMMETRICKEY SCHEMES WITH ONLINE CLASSICAL QUERIES AND ...
 
Solutions to byzantine agreement problem
Solutions to byzantine agreement problem Solutions to byzantine agreement problem
Solutions to byzantine agreement problem
 
Python lec1
Python lec1Python lec1
Python lec1
 

Viewers also liked

Viewers also liked (14)

Zero to a Billion in 4.86 Years (A Whirlwind History of Operating Systems)
Zero to a Billion in 4.86 Years (A Whirlwind History of Operating Systems)Zero to a Billion in 4.86 Years (A Whirlwind History of Operating Systems)
Zero to a Billion in 4.86 Years (A Whirlwind History of Operating Systems)
 
Invent the Future (Operating Systems in 2029)
Invent the Future (Operating Systems in 2029)Invent the Future (Operating Systems in 2029)
Invent the Future (Operating Systems in 2029)
 
Microkernels and Beyond
Microkernels and BeyondMicrokernels and Beyond
Microkernels and Beyond
 
Writing External Rsyslog Plugins
Writing External Rsyslog PluginsWriting External Rsyslog Plugins
Writing External Rsyslog Plugins
 
Basis Linux (aan de hand van LPIC-1)
Basis Linux (aan de hand van LPIC-1)Basis Linux (aan de hand van LPIC-1)
Basis Linux (aan de hand van LPIC-1)
 
Gash Has No Privileges
Gash Has No PrivilegesGash Has No Privileges
Gash Has No Privileges
 
Managing Memory
Managing MemoryManaging Memory
Managing Memory
 
Making a Process (Virtualizing Memory)
Making a Process (Virtualizing Memory)Making a Process (Virtualizing Memory)
Making a Process (Virtualizing Memory)
 
Storage
StorageStorage
Storage
 
Segmentation Faults, Page Faults, Processes, Threads, and Tasks
Segmentation Faults, Page Faults, Processes, Threads, and TasksSegmentation Faults, Page Faults, Processes, Threads, and Tasks
Segmentation Faults, Page Faults, Processes, Threads, and Tasks
 
System Calls
System CallsSystem Calls
System Calls
 
System calls
System callsSystem calls
System calls
 
Securing Syslog On FreeBSD
Securing Syslog On FreeBSDSecuring Syslog On FreeBSD
Securing Syslog On FreeBSD
 
embedded Linux, van Black Tot QA
embedded Linux, van Black Tot QAembedded Linux, van Black Tot QA
embedded Linux, van Black Tot QA
 

Similar to Bakers and Philosophers

Updatedpython.pptxUpdatedpython.pptxUpdatedpython.pptx
Updatedpython.pptxUpdatedpython.pptxUpdatedpython.pptxUpdatedpython.pptxUpdatedpython.pptxUpdatedpython.pptx
Updatedpython.pptxUpdatedpython.pptxUpdatedpython.pptx
ZahouAmel1
 
ESCM303 Introduction to Python Programming.pptx
ESCM303 Introduction to Python Programming.pptxESCM303 Introduction to Python Programming.pptx
ESCM303 Introduction to Python Programming.pptx
AvijitChaudhuri3
 

Similar to Bakers and Philosophers (20)

Blueprints: Introduction to Python programming
Blueprints: Introduction to Python programmingBlueprints: Introduction to Python programming
Blueprints: Introduction to Python programming
 
On the Necessity and Inapplicability of Python
On the Necessity and Inapplicability of PythonOn the Necessity and Inapplicability of Python
On the Necessity and Inapplicability of Python
 
On the necessity and inapplicability of python
On the necessity and inapplicability of pythonOn the necessity and inapplicability of python
On the necessity and inapplicability of python
 
Python4HPC.pptx
Python4HPC.pptxPython4HPC.pptx
Python4HPC.pptx
 
Updatedpython.pptxUpdatedpython.pptxUpdatedpython.pptx
Updatedpython.pptxUpdatedpython.pptxUpdatedpython.pptxUpdatedpython.pptxUpdatedpython.pptxUpdatedpython.pptx
Updatedpython.pptxUpdatedpython.pptxUpdatedpython.pptx
 
Class[1][23ed may] [algorithms]
Class[1][23ed may] [algorithms]Class[1][23ed may] [algorithms]
Class[1][23ed may] [algorithms]
 
W1-Intro to python.pptx
W1-Intro to python.pptxW1-Intro to python.pptx
W1-Intro to python.pptx
 
python ppt
python pptpython ppt
python ppt
 
Mastering Python lesson 3a
Mastering Python lesson 3aMastering Python lesson 3a
Mastering Python lesson 3a
 
ch5.ppt
ch5.pptch5.ppt
ch5.ppt
 
Python4HPC.pptx
Python4HPC.pptxPython4HPC.pptx
Python4HPC.pptx
 
Python Summer Internship
Python Summer InternshipPython Summer Internship
Python Summer Internship
 
Acm aleppo cpc training introduction 1
Acm aleppo cpc training introduction 1Acm aleppo cpc training introduction 1
Acm aleppo cpc training introduction 1
 
03 Operators and expressions
03 Operators and expressions03 Operators and expressions
03 Operators and expressions
 
MITx 6.00.1x Introduction to Computer Science and Programming Using Python - ...
MITx 6.00.1x Introduction to Computer Science and Programming Using Python - ...MITx 6.00.1x Introduction to Computer Science and Programming Using Python - ...
MITx 6.00.1x Introduction to Computer Science and Programming Using Python - ...
 
07 control+structures
07 control+structures07 control+structures
07 control+structures
 
ESCM303 Introduction to Python Programming.pptx
ESCM303 Introduction to Python Programming.pptxESCM303 Introduction to Python Programming.pptx
ESCM303 Introduction to Python Programming.pptx
 
ForLoops.pptx
ForLoops.pptxForLoops.pptx
ForLoops.pptx
 
Python functional programming
Python functional programmingPython functional programming
Python functional programming
 
CrashCourse: Python with DataCamp and Jupyter for Beginners
CrashCourse: Python with DataCamp and Jupyter for BeginnersCrashCourse: Python with DataCamp and Jupyter for Beginners
CrashCourse: Python with DataCamp and Jupyter for Beginners
 

More from David Evans

More from David Evans (20)

Cryptocurrency Jeopardy!
Cryptocurrency Jeopardy!Cryptocurrency Jeopardy!
Cryptocurrency Jeopardy!
 
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for CypherpunksTrick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
 
Hidden Services, Zero Knowledge
Hidden Services, Zero KnowledgeHidden Services, Zero Knowledge
Hidden Services, Zero Knowledge
 
Anonymity in Bitcoin
Anonymity in BitcoinAnonymity in Bitcoin
Anonymity in Bitcoin
 
Midterm Confirmations
Midterm ConfirmationsMidterm Confirmations
Midterm Confirmations
 
Scripting Transactions
Scripting TransactionsScripting Transactions
Scripting Transactions
 
How to Live in Paradise
How to Live in ParadiseHow to Live in Paradise
How to Live in Paradise
 
Bitcoin Script
Bitcoin ScriptBitcoin Script
Bitcoin Script
 
Mining Economics
Mining EconomicsMining Economics
Mining Economics
 
Mining
MiningMining
Mining
 
The Blockchain
The BlockchainThe Blockchain
The Blockchain
 
Becoming More Paranoid
Becoming More ParanoidBecoming More Paranoid
Becoming More Paranoid
 
Asymmetric Key Signatures
Asymmetric Key SignaturesAsymmetric Key Signatures
Asymmetric Key Signatures
 
Introduction to Cryptography
Introduction to CryptographyIntroduction to Cryptography
Introduction to Cryptography
 
Class 1: What is Money?
Class 1: What is Money?Class 1: What is Money?
Class 1: What is Money?
 
Multi-Party Computation for the Masses
Multi-Party Computation for the MassesMulti-Party Computation for the Masses
Multi-Party Computation for the Masses
 
Proof of Reserve
Proof of ReserveProof of Reserve
Proof of Reserve
 
Silk Road
Silk RoadSilk Road
Silk Road
 
Blooming Sidechains!
Blooming Sidechains!Blooming Sidechains!
Blooming Sidechains!
 
Useful Proofs of Work, Permacoin
Useful Proofs of Work, PermacoinUseful Proofs of Work, Permacoin
Useful Proofs of Work, Permacoin
 

Recently uploaded

一比一原版查尔斯特大学毕业证如何办理
一比一原版查尔斯特大学毕业证如何办理一比一原版查尔斯特大学毕业证如何办理
一比一原版查尔斯特大学毕业证如何办理
hwoudye
 
Top profile Call Girls In Kharagpur [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Kharagpur [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In Kharagpur [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Kharagpur [ 7014168258 ] Call Me For Genuine Models...
gajnagarg
 
Top profile Call Girls In Deoghar [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In Deoghar [ 7014168258 ] Call Me For Genuine Models W...Top profile Call Girls In Deoghar [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In Deoghar [ 7014168258 ] Call Me For Genuine Models W...
gajnagarg
 

Recently uploaded (20)

High Profile Call Girls Service in Sangli 9332606886 HOT & SEXY Models beaut...
High Profile Call Girls Service in Sangli  9332606886 HOT & SEXY Models beaut...High Profile Call Girls Service in Sangli  9332606886 HOT & SEXY Models beaut...
High Profile Call Girls Service in Sangli 9332606886 HOT & SEXY Models beaut...
 
一比一原版查尔斯特大学毕业证如何办理
一比一原版查尔斯特大学毕业证如何办理一比一原版查尔斯特大学毕业证如何办理
一比一原版查尔斯特大学毕业证如何办理
 
原版1:1定制(IC大学毕业证)帝国理工学院大学毕业证国外文凭复刻成绩单#电子版制作#留信入库#多年经营绝对保证质量
原版1:1定制(IC大学毕业证)帝国理工学院大学毕业证国外文凭复刻成绩单#电子版制作#留信入库#多年经营绝对保证质量原版1:1定制(IC大学毕业证)帝国理工学院大学毕业证国外文凭复刻成绩单#电子版制作#留信入库#多年经营绝对保证质量
原版1:1定制(IC大学毕业证)帝国理工学院大学毕业证国外文凭复刻成绩单#电子版制作#留信入库#多年经营绝对保证质量
 
Charbagh \ Book Call Girls in Lucknow Finest Escorts Service 9548273370 Avail...
Charbagh \ Book Call Girls in Lucknow Finest Escorts Service 9548273370 Avail...Charbagh \ Book Call Girls in Lucknow Finest Escorts Service 9548273370 Avail...
Charbagh \ Book Call Girls in Lucknow Finest Escorts Service 9548273370 Avail...
 
Call Girls Pune ( 8250092165 ) Cheap rates call girls | Get low budget
Call Girls Pune ( 8250092165 ) Cheap rates call girls | Get low budgetCall Girls Pune ( 8250092165 ) Cheap rates call girls | Get low budget
Call Girls Pune ( 8250092165 ) Cheap rates call girls | Get low budget
 
Nalasopara Call Girls , 07506202331, Vasai Vip Housewife Call Girls
Nalasopara Call Girls , 07506202331, Vasai Vip Housewife Call GirlsNalasopara Call Girls , 07506202331, Vasai Vip Housewife Call Girls
Nalasopara Call Girls , 07506202331, Vasai Vip Housewife Call Girls
 
Call Girls Bhavnagar - 8250092165 Our call girls are sure to provide you with...
Call Girls Bhavnagar - 8250092165 Our call girls are sure to provide you with...Call Girls Bhavnagar - 8250092165 Our call girls are sure to provide you with...
Call Girls Bhavnagar - 8250092165 Our call girls are sure to provide you with...
 
Call girls Service Nadiad / 8250092165 Genuine Call girls with real Photos an...
Call girls Service Nadiad / 8250092165 Genuine Call girls with real Photos an...Call girls Service Nadiad / 8250092165 Genuine Call girls with real Photos an...
Call girls Service Nadiad / 8250092165 Genuine Call girls with real Photos an...
 
Call Girls in Moshi - 8250092165 Our call girls are sure to provide you with ...
Call Girls in Moshi - 8250092165 Our call girls are sure to provide you with ...Call Girls in Moshi - 8250092165 Our call girls are sure to provide you with ...
Call Girls in Moshi - 8250092165 Our call girls are sure to provide you with ...
 
Call Girls in Morbi - 8250092165 Our call girls are sure to provide you with ...
Call Girls in Morbi - 8250092165 Our call girls are sure to provide you with ...Call Girls in Morbi - 8250092165 Our call girls are sure to provide you with ...
Call Girls in Morbi - 8250092165 Our call girls are sure to provide you with ...
 
Top profile Call Girls In Kharagpur [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Kharagpur [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In Kharagpur [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Kharagpur [ 7014168258 ] Call Me For Genuine Models...
 
Top Call Girls in Tribeniganj 9332606886 High Profile Call Girls You Can G...
Top Call Girls in Tribeniganj   9332606886  High Profile Call Girls You Can G...Top Call Girls in Tribeniganj   9332606886  High Profile Call Girls You Can G...
Top Call Girls in Tribeniganj 9332606886 High Profile Call Girls You Can G...
 
Unlimited Short Call Girls in Jamnagar { 9332606886 } VVIP NISHA Call Girls N...
Unlimited Short Call Girls in Jamnagar { 9332606886 } VVIP NISHA Call Girls N...Unlimited Short Call Girls in Jamnagar { 9332606886 } VVIP NISHA Call Girls N...
Unlimited Short Call Girls in Jamnagar { 9332606886 } VVIP NISHA Call Girls N...
 
Call Girls in Anand - 8250092165 Our call girls are sure to provide you with ...
Call Girls in Anand - 8250092165 Our call girls are sure to provide you with ...Call Girls in Anand - 8250092165 Our call girls are sure to provide you with ...
Call Girls in Anand - 8250092165 Our call girls are sure to provide you with ...
 
independent Call Girls West Sikkim 9332606886 ust Genuine Escort Model Sevice
independent Call Girls West Sikkim  9332606886  ust Genuine Escort Model Seviceindependent Call Girls West Sikkim  9332606886  ust Genuine Escort Model Sevice
independent Call Girls West Sikkim 9332606886 ust Genuine Escort Model Sevice
 
Call Girls in Rajpur Sonarpur / 8250092165 Genuine Call girls with real Photo...
Call Girls in Rajpur Sonarpur / 8250092165 Genuine Call girls with real Photo...Call Girls in Rajpur Sonarpur / 8250092165 Genuine Call girls with real Photo...
Call Girls in Rajpur Sonarpur / 8250092165 Genuine Call girls with real Photo...
 
Top profile Call Girls In Deoghar [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In Deoghar [ 7014168258 ] Call Me For Genuine Models W...Top profile Call Girls In Deoghar [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In Deoghar [ 7014168258 ] Call Me For Genuine Models W...
 
HiFi Call Girl Service Hyderabad | Whatsapp No 📞 9352988975 📞 VIP Escorts Ser...
HiFi Call Girl Service Hyderabad | Whatsapp No 📞 9352988975 📞 VIP Escorts Ser...HiFi Call Girl Service Hyderabad | Whatsapp No 📞 9352988975 📞 VIP Escorts Ser...
HiFi Call Girl Service Hyderabad | Whatsapp No 📞 9352988975 📞 VIP Escorts Ser...
 
Call girls Service Bhosari ( 8250092165 ) Cheap rates call girls | Get low bu...
Call girls Service Bhosari ( 8250092165 ) Cheap rates call girls | Get low bu...Call girls Service Bhosari ( 8250092165 ) Cheap rates call girls | Get low bu...
Call girls Service Bhosari ( 8250092165 ) Cheap rates call girls | Get low bu...
 
Foreigner Call Girls in junagadh 8250092165 Call Girls Advance Cash On Deliv...
Foreigner Call Girls in junagadh  8250092165 Call Girls Advance Cash On Deliv...Foreigner Call Girls in junagadh  8250092165 Call Girls Advance Cash On Deliv...
Foreigner Call Girls in junagadh 8250092165 Call Girls Advance Cash On Deliv...
 

Bakers and Philosophers

  • 1.
  • 2. Plan for Today Dijkstra’s Mutual Exclusion Solution Lamport’s Solution Dining Philosophers 1 Reminder: Everyone should have scheduled a project progress meeting!
  • 3. Project Update Every team should have a progress/review meeting scheduled – Discuss what you have done so far and plans to finish Project submission: – Web form (including link to github repo or other web content): accepted without penalty until Monday, 5 May (11:59pm) – Option of either: In-class presentation/demo (April 24 or April 29) Formal written report (due April 29, 11:59pm) Something else 2 No final exam, unless your project is embarrassing. Then you’ll have a chance to make up for it by doing a final exam. You have until Monday (Apr 21) to submit a form with your preferences, but priority will be given to earlier submissions!
  • 4. Why so much on mutual exclusion? 3
  • 5. 4
  • 6. 5
  • 7. 6 Program for Processor i loop { b[i] := false L1: if k != i c[i] := true if b[k]: k := i goto L1 else: c[i] := false; L4: for j in [1, …, N]: if j != i and not c[j]: goto L1 critical section; c[i] := true b[i] := true } How do we know none of the c[.]’s changed during the loop? Where we got last class:
  • 8. 7 Program for Processor i loop { 1: b[i] := false 2: if k != i: 3: c[i] := true 4: if b[k]: 5: k := i 6: goto L2 else: 7: c[i] := false; 8: for j in [1, …, N]: 9: if j != i and not c[j]: 10: goto L2 11: critical section; 12: c[i] := true 13: b[i] := true } How do we know none of the c[.]’s changed during the loop?
  • 9. 8 Program for Processor i loop { b[i] := false L1: if k != i c[i] := true if b[k]: k := i goto L1 else: c[i] := false; L4: for j in [1, …, N]: if j != i and not c[j]: goto L1 critical section; c[i] := true b[i] := true }
  • 10. 9 Liveness ProofProgram for Processor i loop { b[i] := false L1: if k != i c[i] := true L3: if b[k]: k := i goto L1 else: c[i] := false; L4: for j in [1, …, N]: if j != i and not c[j]: goto L1 critical section; c[i] := true b[i] := true }
  • 11. 10 Assumptions? Program for Processor i loop { b[i] := false L1: if k != i c[i] := true L3: if b[k]: k := i goto L1 else: c[i] := false; L4: for j in [1, …, N]: if j != i and not c[j]: goto L1 critical section; c[i] := true b[i] := true }
  • 12. 11 “When I was at Compass, I read a paper in Communications of the ACM about a mutual-exclusion algorithm,” Lamport recalls. “It was the first time I had seen the mutual-exclusion problem, and I looked at it and said, ‘Well, that doesn’t seem very difficult.’”
  • 13. 12 “What is significant about the bakery algorithm is that it implements mutual exclusion without relying on any lower-level mutual exclusion. Assuming that reads and writes of a memory location are atomic actions, as previous mutual exclusion algorithms had done, is tantamount to assuming mutually exclusive access to the location. So a mutual exclusion algorithm that assumes atomic reads and writes is assuming lower-level mutual exclusion. Such an algorithm cannot really be said to solve the mutual exclusion problem. Before the bakery algorithm, people believed that the mutual exclusion problem was unsolvable--that you could implement mutual exclusion only by using lower-level mutual exclusion.”Communications of the ACM, August 1974 (2 pages)
  • 14. 13
  • 15. 14
  • 16. 15 T2 T3 T4T1 N independent threads Shared Memory (no exclusion!) T5 Program: loop { non-critical { … } critical { … } } Requirements: 1. Only one thread may be in the critical section at any time. 2. Each must eventually be able to enter its critical section. 3. Must be symmetrical (all run same program). 4. Cannot make any assumptions about speed of threads. 5. Only writes are guaranteed (when simultaneous).
  • 18. 17 If the write changes the value from 0 to 1, a concurrent read could obtain the value 7456 (assuming that 7456 is a value that could be in the memory location). The algorithm still works. I didn't try to devise an algorithm with this property. I discovered that the bakery algorithm had this property after writing a proof of its correctness and noticing that the proof did not depend on what value is returned by a read that overlaps a write.
  • 19. 18
  • 20. 19
  • 21. 20
  • 22. 21 How could number[i] = number[k]?
  • 23. 22
  • 24. 23
  • 25. 24
  • 26. 25
  • 27. 26Sir Tony Hoare (born 1934)
  • 28. 27
  • 30. 29 5 Dining Philosophers 5 Chopsticks (one between each pair) Need 2 chopsticks to eat
  • 32. 31 No (extra) communication No deadlock No starvation Fair
  • 33. Djikstra’s (Hygenic) Version EWD625 32 Is this equivalent to the shared chopsticks?
  • 34. Solution Desiderata No communication required No deadlock No starvation: everyone gets to eat eventually Fair: each philosopher has equal likelihood of getting to eat 33
  • 35. Dijkstra’s Solution (Idea) Number the chopsticks Always grab lower-numbered stick first 34 Does it matter how the chopsticks are numbered?
  • 36. The Real Idea was to “Invent the Chopstick” Binary Semaphore Lock that can be held by up to one process 35 http://commons.wikimedia.org/wiki/File:Chopstick.png
  • 37. Charge 36 Many more interesting problems and solutions in distributed algorithms: Consensus Leader election Reliable broadcast … Next class: Microkernels, Exokernels, and “Zepto”-kernels Hardware solutions only help when all threads are running on the same processor