0
$\begingroup$

According to wikipedia, Lamport clocks need to be incremented when sending a message (time = time + 1) and when receiving a message (time = max(time_stamp, time) + 1).

In my implementation, Increment() is used when sending and Witness() is used when receiving, each of them following the previous rules.

I can't understand why not only Increment() actually increment the counter, that is why Witness() does not simply do time = max(time_stamp, time) instead of time = max(time_stamp, time) + 1.

The source of my confusion is the following scenario:

  • clock start at 1
  • a message is sent, clock is at 2
  • this message is seen locally, clock is now at 3

In this scenario, the clock incremented twice for the same message. Ideally it would just be one. Did I break something by witnessing the clock within the same process? Did I get something wrong?

$\endgroup$

1 Answer 1

0
$\begingroup$

From Leslie Lamport Time, Clocks, and the Ordering of Events in a Distributed System:

The space-time diagram of Figure 1 might then yield the picture in Figure 2. Condition C 1 means that there must be a tick line between any two events on a process line, and condition C2 means that every message line must cross a tick line.

I think my confusion was on what actually is an event.

In Lamport's paper and in Wikipedia, sending and receiving the messages are the events. In that case, incrementing the counter both when sending and receiving a message makes sense, to ensure that a clock tick separates those events.

In my case, the data structure modifications are the events. The message passing between the processes is irrelevant. In that case, I believe that incrementing the counter only when the data changes makes sense.

Now, if applying Lamport's clock principle this way still qualifies as Lamport's clock and holds all the related properties, I do not know.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.