next up previous contents
Next: Java: System Design Up: Distributed Systems Previous: Systems/Networks   Contents

Distributed Coordination [235]





LeLann's Mutual Exclusion [236]

At all i:                              Extra code at i=1:

                                       send({\em neighbor, TOKEN})

    do forever  {

                                        cycles <- cycles - 1

                                        if cycles = 0 then send(neighbor, STOP)


      msg <- receive()

      /* critical section */
   
      send(neighbor,msg)

      if msg = STOP then goto EXIT


    }

    EXIT: destroy(i)



Lamport's Logical Register [237]


\begin{picture}(324,204)(38,618)
\thicklines\put( 60,720){\circle{44}}
\put( 60,...
...ut(180,675){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{$\vdots$}}}
\end{picture}



Lamport's Logical Register [238]

At register process x_i in {1,...,n}:
   
   do forever

     message <- receive()

     if message = READ then send(reader, x)

     else {     /* message is the value to be written */

       x <- message

       send(writer, DONE)

     }

At reading process j in {n+1,...,2n}:
   
   do forever

     send(register, READ)

     value <- receive()

At writing process k=2n+1:
   
   do forever

     /* compute new value */

     for i=1,...,n do send(i, value)

     for i=1,...,n do message <- receive()



Coordination: Leader Election [239]

Given: n processes on a ring, each with unique identifier

Problem: elect a leader





\begin{picture}(135,140)(15,685)
\thicklines\put( 20,820){\circle*{10}}
\put( 20...
...ebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\em next\_next\_temp\_id}}}
\end{picture}



LeLann's Leader Election [240]

Local Variables:

1. temp_id <- i, the temporary ID of the process

2. next_temp_id, the temporary ID of the next clockwise process

3. neighbor <- i+1, the next counterclockwise process on the ring 

At p_i in {1,...,n}:

   send(neighbor, temp_id)

   do forever

     next_temp_id <- receive()

     if next_temp_id > temp_id then send(neighbor, next_temp_id)

     if next_temp_id = temp_id then announce( LEADER)



Peterson's Leader Election [241]

  ACTIVE:

  do forever

    send(neighbor, temp_id)

    next_temp_id <- receive()

    if next_temp_id = temp_id then

      announce(LEADER)

    send(neighbor, next_temp_id)

    next_next_temp_id <- receive()

    if next_temp_id > max(temp_id, next_next_temp_id) then

      temp_id <- next_temp_id

    else

       goto RELAY

  
  RELAY:

  do forever

    temp_id <- receive()

    send(neighbor, temp_id)


next up previous contents
Next: Java: System Design Up: Distributed Systems Previous: Systems/Networks   Contents
Ted Billard 2001-11-17