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]
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
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)