The problem If one or more philosophers try to to e at - - PDF document

the problem if one or more philosophers try to to e at
SMART_READER_LITE
LIVE PREVIEW

The problem If one or more philosophers try to to e at - - PDF document

The problem If one or more philosophers try to to e at then one of them ev en tually after a nite time succeeds No Deadlo c k The ab o v e prop ert y do es not pro vide an y guaran tee


slide-1
SLIDE 1
  • The
problem If
  • ne
  • r
more philosophers try to to e at then
  • ne
  • f
them ev en tually after a nite time succeeds No Deadlo c k The ab
  • v
e prop ert y do es not pro vide an y guaran tee
  • n
an individual basis since a pro cessor ma y try to eat and y et fail since it alw a ys b ypassed b y
  • ther
philosophers What w e w
  • uld
lik e to ha v e is a stronger prop ert y
  • whic
h implies no deadlo c k No Starv ation If a philosopher wishes to eat then it will ev en tually after a nite time succeed as long as no philosopher k eeps eating forev er W e assume that eac h philosopher eats for at most
  • time
units
  • DS
I I L Philippas Tsigas
slide-2
SLIDE 2
  • Symmetry
W e sa y that a solution to a distributed problem is symmetric if
  • all
pro cesses are iden tical nothing that distinguishes
  • ne
computer from the
  • ther
  • all
pro cesses run the same co de
  • all
shared
  • r
lo cal v ariables ha v e the same input v alue DS I I L Philippas Tsigas
slide-3
SLIDE 3
  • Imp
  • ssibilit
y Result There is no symmetric solution to the dinning philosophers problem Pro
  • f
Assume for the purp
  • se
  • f
con tradiction that there is a solution A Consider a roundrobin execution
  • f
A in whic h rst philosopher p
  • mak
es its rst step then p
  • then
p n
  • W
e can pro v e b y induction that after this rst round all philosophers are going to b e in the same state and all links are going to ha v e the same messages No w w e can pro v e again b y induction
  • n
the n um b er
  • f
rounds that at the end
  • f
eac h round all philosophers are alw a y going to b e in the same state The last
  • ne
means that if philosopher p i at some p
  • in
t starts eating its neigh b
  • urs
will start eating together with him b y the end
  • f
the resp ectiv e round Contr adiction Accessible common resources are referred n y the pro cesses with their lo cal DS I I L Philippas Tsigas
slide-4
SLIDE 4
  • names
DS I I L Philippas Tsigas
slide-5
SLIDE 5
  • Righ
tLeft DP Proto col F
  • r
simplicit y n is ev en W e giv e dieren t proto cols to the philosophers
  • ne
for the philosophers that w e call with
  • dd
indices and
  • ne
for those with ev en indices The basic strategy is v ery simple Oddnumb er e d philosophers seek their righ t fork rst Evennumb er e d philosophers seek their left fork rst A philosopher seeks a c hopstic k b y putting its id at the end
  • f
that c hopstic ks queue The philosopher
  • btains
the c hopstic k when its index reac hes the fron t
  • f
that c hopstic ks queue When a philosopher nishes eating it returns b
  • th
c hopstic ks b y remo ving its index from their queues DS I I L Philippas Tsigas
slide-6
SLIDE 6
  • Time
Complexit y IDEA A c hopstic k b et w een t w
  • philosophers
is either the rst c hopstic k for b
  • th
  • r
the second c hopstic k for b
  • th
Time Complexit y Roughly
  • DS
I I L Philippas Tsigas
slide-7
SLIDE 7
  • Same
co de to the pro cesses Y
  • u
can ask from y
  • ur
system philosophers to get unique names from the range n
  • But
this is not going to b e lo c al b ecause the philosophers ha v e to learn n Y
  • u
can ask from y
  • ur
pro cesses to get a color from the set
  • f
colours P
  • f
bl ack
  • w
hite g so that no t w
  • neigh
b
  • urs
get the same color Can this b e done DS I I L Philippas Tsigas
slide-8
SLIDE 8
  • Dinning
Philosophers Cn t W e can ha v e a solution to the dinning philosophers problem if w e start with a Black
  • White
coloring
  • f
the ring The Black
  • White
coloring can b e seen as a prepro cessing phase though that need to b e done from the system when philosophers lea v e the table
  • r
new
  • nes
are joining On aver age if b et w een t w
  • coloring
phases pro cesses sp end time prop
  • rtional
to n at the table
  • DS
I I L Philippas Tsigas
slide-9
SLIDE 9
  • Philosophers
vs Chopstic ks Let us ha v e lo
  • k
at the algorithm that w e describ ed in the previous lecture The algorithm lo
  • k
ed lik e this
  • Hungry
  • Get
a Black
  • White
color if y
  • u
do not ha v e
  • ne
  • If
y
  • u
are Black seek righ t c hopstic k rst
  • if
y
  • u
are White seek left c hopstic k rst
  • After
nish eating put the c hopstic k bac k DS I I L Philippas Tsigas
slide-10
SLIDE 10
  • Philosophers
vs Chopstic ks Cn t A new algorithm
  • Hungry
  • Giv
e a Black
  • White
consisten t color to y
  • ur
c hopstic ks if y
  • u
ha v e not done that
  • Seek
Black c hopstic k rst Remem b er The ide a
  • f
the rst algorithm w as that a c hopstic k b et w een t w
  • philosophers
is either the rst here blac k c hopstic k for b
  • th
  • r
the second here white c hopstic k for b
  • th
DS I I L Philippas Tsigas
slide-11
SLIDE 11
  • Ho
w do I color c hopstic ks DS I I L Philippas Tsigas
slide-12
SLIDE 12
  • Resource
Allo cation Generalising the Dinning Philosophers A resource allo cation problem consists
  • f
a nite set
  • f
r esour c es and some comp eting pr
  • c
esses Pro cesses request access to the resources from time to time in
  • rder
to execute a co de segmen t called critic al se ction Up
  • n
b eing gran ted all the requested resources a pro cess pro ceeds to use them and ev en tually relinquishes them Requiremen ts
  • Mutual
exclusion No resource should b e accessed b y more than
  • ne
pro cess at the same time
  • No
Starv ation As long as pro cesses do not fail no pro cess should w ait forev er for requested resources DS I I L Philippas Tsigas
slide-13
SLIDE 13
  • Resource
Allo cation Solution W e generalise in a straigh tforw ard w a y the Righ tLeft Dinning philosophers algorithm to an arbitrary resource allo cation problem W e rst construct the Resource Graph
  • The
no des
  • f
this graph represen t the resources
  • There
is a no de from
  • ne
no de to another if there is some pro cess that uses b
  • th
the resources DS I I L Philippas Tsigas
slide-14
SLIDE 14
  • Coloring
again W e no decolor the r esour c e gr aph DS I I L Philippas Tsigas
slide-15
SLIDE 15
  • The
Generalisation Eac h pro cess seeks its resources in increasing
  • rder
according to the total
  • rdering
constructed b y the coloring A pro cess seeks a resource b y putting its index at the end
  • f
that resources queue The pro cess
  • btains
the resource when its index reac hes the fron t
  • f
that resources queue When a pro cess exits C it returns all
  • f
its resources b y remo ving its index from their queues Let us assume that k is the maxim um n um b er
  • f
pro cesses that require an y single resource What is the time complexit y
  • f
the algorithm DS I I L Philippas Tsigas