Lecture10 LogicalClock
Lecture10 LogicalClock
a) The time daemon asks all the other machines for their clock values
b) The machines answer
c) The time daemon tells everyone how to adjust their clock
Limitation
• They all require network delay to be stable to
some extent
p0
Ask Grant
p1
Ask
Ask
p2
Counter example
No deadlock: good
Monitor
p0->p1 p1->p2 p2->p0
remove
p0->p1
p0
Ask Grant
p1
Ask
Ask
p2
Counter example
Deadlock: false alarm
Monitor
p0
Ask Grant
p1
Ask
Ask
p2
Solution: Causal delivery
• Definition: sendi(m) → sendj(m’) deliverk(m)
→ deliverk(m’)
• Is this complete?
Start with stronger assumptions
• Attach a timestamp ts to each message
(1,1) (1,0)
Monitor
(1,0)
p0
p1
(1,1)
Properties of vector clock
• Property 1 (Strong Clock Condition)
– e→e’ ≡ VC(e) < VC(e’)
• Property 2 (Simple Strong Clock Condition)
– ei →ej ≡ VC(ei)[i]≤VC(ej)[i]
– Can you prove it?
• Property 3 (Concurrent)
– ei||ej ≡(VC(ei)[i] > VC(ej)[i]) (VC(ej)[j] > VC(ei)[j])
Properties of vector clock
• Properties 4 - 6: Read the paper. 4 and 5 are
used to determine whether a cut is consistent.
Lock() Lock()
Write x Write x
this is perfectly safe
Y=x+5 Unlock()
Unlock()
• Accessing shared variable without locks is
called a data race
– It is usually a bug.
– How to detect it?
Open Questions
• How to use Vector Clocks
– What are messages here?
• How to be efficient about this
– There can be too many memory accesses
Basic idea
• If there is a happened-before relationship
between conflicting operations, then no
problem. Otherwise, data race.