Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
time
Lamports Logical Clock
Logical clock Ci associated with Pi
Clock condition for implementing ->
C(a) < C(b) if a -> b
is converse true?
If a and b are events in same process
Condition 1: Ci(a) < Ci(b)
Pi increments Ci between successive events
If a and b are message send and receive events
from Pi to Pj
Condition 2: Ci(a) < Cj(b)
Tm = Ci(a) =Ci (timestamp associated with message)
Cj(b) = MAX (Tm++, Cj)
Possible alternatives
Total order (=>)
a => b (a in Pi and b in Pj) iff
1. Ci(a) < Cj(b) or
2. Ci(a) = Cj(b) and Pi << Pj
(<< is an arbitrary total ordering of
processes to break a tie)
arbitrarily break ties total order (=>) of events is
established
a and b not causally related, so it doesnt matter, and there is
no way to know exactly which one happened before
To establish total ordering (=>) assume unique (though
arbitrary) ordering of processes Pi < Pj
An example
P1 P2 P3
a, 1
Total order?
b, 2
c, 3
f, 4
d, 5 e, 5
Distributed M.E. algorithm
Every process Pi has a request Qi
Qi private to Pi ordered by ->
Requests and acks timestamped by Ci
Logical clocks used to maintain ->
Acquiring M.E. Lock
1. Pi sends request Li(Tl) to all other
processes and puts it in Qi
2. Every Pj receives Li(Tl); places Li in Qj;
acks Aj(Tl+1) back to Pi
3. Pi can access resource when
a) Li is at the head of Qi
and
b) Pi has received messages from ALL Pj with
timestamp > Tl
Releasing M.E. Lock
4. Pi removed Li from Qi; send release
Ui(Tu) to all Pj
5. Every Pj removes Li from its Qj
Correctness Notes
Messages arrive in order between any pair
of processes
3b ensures that Pi knows all requests prior
to its own
The queues are totally ordered derived
from the -> relation
Message complexity
L messages N-1
A messages N-1
U messages N-1
Total = 3 (N-1)
Can we do better?
Why is Total Order important:
Distributed Coordination
Mutual exclusion example
Must give access to resource in order in which requests are made
P1 msg to sched P0, P1 msg to P2, then P2 msg to P0, P0 receives
P2s msg first
Distributed implementation:
Send timestamped msg to everyone, also put it in your request queue
Get timestamped acks from everyone that they are aware of your
request
When your request is on front of your queue, you have access
When done with resource send timestamp release msg to everyone
On release msg everyone removes corresponding request from
personal queue
Assumptions:
Ordered, lossless communication!
No faulty processors
No external communication channels
Or explicit update if external comm exists
Dealing with the real world
P1 P2
C2 = 8
debit
C1 = 5
credit
time
bank1 bank2
debit C2 = 8
C1 = 5
credit
server
time
Physical clock
Strong clock condition:
For a |-> b we need Ci(a) < Cj(b)
credit
5 10 mj
4
6 7 12
mi
time Pi Pj Pk
Example - 2
u = 2; e = 1
2 3 4
5 credit
4
7 debit
6 7 8
mi
mj
time Pi Pj Pk
Condition for Physical Clocks
Physical clocks may have a drift e and change in rate k
Lamport establishes relationship between e and k
relative to the minimal delay of a message : e <= - k
Implementation rules:
At each process, in absence of msgs Ci is differentiable
and slope > 0 (i.e., will increase)
When msg with timestamp Tm is received at time t,
Cj=max(Cj(t-0), Tm+ ) (i.e., explicit update)
Msgs must be sent every sec, and must have
unpredictable delay less than (i.e., how often should
we synchronize)