distributed algorithms
play

DistributedAlgorithms Setofsharedobjects(variables) - PDF document

2/23/09 Distributed Sharedmemory Bertinoro, March 2009 Algorithms Part III 2 Sharedmemorydistributedsystem Setofprocesses DistributedAlgorithms Setofsharedobjects(variables)


  1. 2/23/09
 Distributed Shared
memory
 Bertinoro, March 2009 Algorithms Part III 2
 • Shared
memory
distributed
system
 – Set
of
processes
 Distributed
Algorithms
 – Set
of
shared
objects
(variables)
 • access
to
a
shared
variable
is
a
single
(indivisible)
event
 PART III 
 • CommunicaCon
through
shared
variables
 – No
channels
 SHARED
MEMORY
 • We
use
a
single
automaton
to
model
the
 enCre
system
 – using
several
automata
and
the
composiCon
 operaCon
leads
to
some
(technical)
difficulCes
 1
 Distributed Shared
memory
 Bertinoro, March 2009 Distributed Shared
memory
 Bertinoro, March 2009 Algorithms Algorithms Part III 3
 Part III 4
 Port
1
 Port
2
 Port
 n • However,
we
think
of
each
 p i 
as
an
automaton
 – states i , start i , … • Each
shared
variable
 x 

 – values x , ini0al x , … • binary
values,
arbitrary
values,
bounded,
unbounded
…
 p n p 1
 p 2
 – single/mulCple
 • single‐writer
or
mulCple‐writer
 • single‐reader
or
mulCple‐reader
 – type
(read‐write,
read‐modify‐write,
…)
 • The
overall
system
automaton
A
 – states,
consists
of
a
state
for
each
 p i 
and
a
value
for
each
 shared
variable
 – start,
consists
of
a
start
state
for
each
 p i 
and
an
iniCal
value
 for
each
shared
variable
 Automaton
for
the
enCre
system
 Distributed Shared
memory
 Bertinoro, March 2009 Distributed Shared
memory
 Bertinoro, March 2009 Algorithms Algorithms Part III 5
 Part III 6
 • act(A),
set
of
acCons
 • trans(A)
 – each
acCon
is
“associated”
with
a
 p i – restricted
so
that
only
the
state
of
involved
 process
and
shared
variables
can
be
changed
 • Some
acCons
 – ( s , π , s ’)
is
a
valid
step
for
A
if
( s i , π , s i ’)
is
a
valid
step
 for
 p i – “associated”
also
with
a
(some)
shared
variable(s)
 • π cannot
change
state
of
other
processes
 – π can
access
only
associated
variables
 • Input/output
acCons
of
 p i 
 – “port”
of
process
 i • Technicality
 • Internal
acCons
of
 p i – if
 π associated
with
 p i and
with
shared
variable
 x ,
 – local
computaCon
 then
whether
or
not
 π is
enabled
should
depend
 only
on
the
state
of
 p i and
not
on
 x .


 1


  2. 2/23/09
 Distributed Shared
memory
 Bertinoro, March 2009 Distributed Shared
memory
 Bertinoro, March 2009 Algorithms Algorithms Part III 7
 Part III 8
 SharedVarConsensus
automaton
 • tasks(A)
 States,
for
each
 i :
 


 status i ∈ 
{ idle,access,decide,done },
iniCally
 idle 
 – task
structure
consistent
with
process
structure
 


 input i ∈ 
V
 ∪ 
{ ⊥ } , iniCally ⊥ 
 


 output i ∈ 
V
 ∪ 
{ ⊥ } , iniCally ⊥ – each
equivalence
class
should
include
only
acCons
 Shared
variables: 
 associated
with
a
process
 


x
 ∈ 
V
 ∪ 
{ ⊥ } , iniCally ⊥ ,
accessible
by
all
processes
 • that
is
an
equivalence
class
cannot
contain
acCons
of
 p i 
 Transi=ons,
for
each
 i : 

 and
acCons
of
 p j .
 inp
 init ( v ) i out decide ( v ) i fect: input i :=
 v Pr e: status i 
=
 decide Ef Effect: Pre: if
 status i 
=
 idle 
then output i 
=
 v status i := access 
 
 
 

 

 Ef Effect: fect: status i 
=
 done 
 Example
 int access i e: status i 
=
 access Pr Pre: Set
of
 n 
processes,
one
shared
variable
 x Ef fect: if x = ⊥ 
then x := input i Effect: output i 
:=
 x Consensus
problem:
 status i 
:=
 decide 
 
port
 i :
 init i ( v ),
 decide i ( v )
 Tasks:
 for
every i, 

 { access i , decide i } 
 Distributed Shared
memory
 Bertinoro, March 2009 Distributed Shared
variables
type
 Bertinoro, March 2009 Algorithms Algorithms Part III 9
 Part III 10
 • We
can
model
the
environment
that
controls
 • Variable
type
 each
process
with
an
automaton
 – set
 V 
of
values
 – an
iniCal
value
 v 0 
 ∈ 
 V – a
set
of
 invoca0ons • For
the
previous
case
we
can
have
 – a
set
of
 responses – Automaton
 U i 
that
controls
 init i 
and
receives
the
 – a
funcCon
 f :
 invoca0ons 
×
 V 
 → 
 responses 
×
 V decide i 
acCons
 – init i 

executed
only
once
 • A
variable
type
is
not
an
automaton
 • Exercise:
write
automaton
code
for
 U i 
 – Looks
similar
 – Invoca=ons
and
responses
occur
together
as
part
 of
a
func=on
applica=on
 Distributed Shared
variable
types
 Bertinoro, March 2009 Distributed Shared
variable
types
 Bertinoro, March 2009 Algorithms Algorithms Part III 11
 Part III 12
 • Read/write
shared
variables
(register)
 • Read‐modify‐write
shared
variables
 – invocaCons
are:
 read 
and
 write ( v )
 – responses
are:
 v (a
value),
 ack – the
funcCon
 f 
allows
to

 – funcCon:

 • read
the
variable
 • f ( read , v )
=( v , v )
 • perform
some
local
computaCon
 • f ( write ( v ), w )=( ack ,v)
 • write
a
new
value
into
the
variable
 • QuesCon
 – all
in
one
step
 – The
shared
variable
used
in
the
Consensus
example
is
a
 read‐write
variable?
 • Difficult
to
implement
 • Exercise:
rewrite
the
code
of
the
Consensus
example
 using
a
read‐write
shared
variable
 – two
accesses
(a
read
and
a
write)
 – Hint
instead
of
one
single
acCon
that
reads
and
writes
 x 
 you
need
two
acCons
(one
for
reading
and
another
for
 wriCng)
 – Can
you
make
it
work?
Show
an
example
where
it
fails.
 2


  3. 2/23/09
 Distributed Shared
variables
type
 Bertinoro, March 2009 Distributed Shared
variables
 Bertinoro, March 2009 Algorithms Algorithms Part III 13
 Part III 14
 • Swap
 f ( u,v )=( v , u )
 • Compare‐and‐swap
 f (( u,v ), w )=
( w , v ),

if
 u = w 
 
 
 
 


















( w , w ),

otherwise
 MUTUAL EXCLUSION AND RESUORCE ALLOCATION 
 • Test‐and‐set
 f ( u,v )=( v ,1)
 • Fetch‐and‐add
 f ( u , v )=( v , u+v )
 Distributed Mutual
Exclusion
 Bertinoro, March 2009 Distributed Mutual
Exclusion
 Bertinoro, March 2009 Algorithms Algorithms Part III 15
 Part III 16
 • Resource
allocaCon
problem
 – single
resource
that
can
support
only
one‐user
at
 • Each
process
has
4
regions
 Remainder
 a
Cme
(e.g.
a
printer)

 – Remainder
 – several
users
 U 1 ,
 U 2 ,
…
, U n 
want
to
access
the
 – Trying
 Trying
 resource
 – CriCcal
 – Exit
 • In
an
“operaCng
systems”
sehng
 CriCcal
 – several
processes
have
a
porCon
of
their
code
 • ExecuCon
loops
in
these
regions
 which
is
called
“criCcal
region”
 Exit
 – no
two
processes
can
concurrently
execute
their
 criCcal
regions
 Distributed Mutual
Exclusion
 Bertinoro, March 2009 Distributed Mutual
Exclusion
 Bertinoro, March 2009 Algorithms Algorithms Part III 17
 Part III 18
 • User
 U i 
issues
 U 1
 U n – try i 
acCons
(request
to
access
the
resource)
 try 1
 exit 1
 try n exit n – exit i 
acCons
(request
to
leave
the
resource)
 crit 1
 rem 1
 crit n rem n • Need
to
output
 – crit i 
(to
grant
the
resource)
 p n p 2
 p 1
 – rem i 
(to
return
to
the
remainder
region)
 • U i 
is
well‐formed
 – if
it
follows
the
cycle
of
acCons
 try i ‐
( crit i )
–
 exit i 
‐
 ( rem i )
 3


Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend