Algorithms
Algorithms
☞ Implementation of logical clocks is performed using the following rules for updating the clocks and
transmitting their values in messages:
[R1]: CPi is incremented before each event is issued at process Pi: CPi := CPi + 1.
[R2]: a) When a is the event of sending a message m from process Pi, then the timestamp tm = CPi(a) is
included in m (CPi(a) is the logical clock value obtained after applying rule R1).
b) On receiving message m by process Pj, its logical clock CPj is updated as follows:
c) The new value of CPj is used to timestamp the event of receiving message m by Pj (applying rule R1).
Vector Clocks
☞ Implementation of vector clocks is performed using the following rules for updating the clocks and
transmitting their values in messages:
[R1]: CvPi is incremented before each event is issued at process Pi: CvPi[i] :=CPi[i] + 1.
from process Pi, then the timestamp tm = CvPi(a) is included in m (CvPi(a)isthevectorclockvalue obtained
after applying rule R1).
b) On receiving message m by process Pj, its vector clock CvPj is updated as follows:
c) The new value of CvPj is used to timestamp the event of receiving message m by Pj (applying rule R1).
Ricart-Agrawala Algorithm
The Algorithm
TPi := the value of the local logical clock corresponding to this request.
[RA2]: Pi sends a request message to all processes; the message is of the form (TPi, i), where i is an
identifier of Pi.
[RA3]: Pi waits until it has received replies from all other n-1 processes.
[RH1]: if statePi = HELD or ((statePi = REQUESTED) and ((TPi, i)< (TPj, j))) then
else
end if.
The Algorithm
/* performed by a process Pi, which triggers the election procedure, or which starts an election after
receiving itself an election message */
else
end if
end if.