The happened-before relation on the events of a run is the smallest transitive relation such that if comes before in the same process, or sends a message that receives. Two distinct events are concurrent events, written , if neither nor . A Lamport clock is a counter in each process: before each event the process adds 1 to it, a message carries the sender’s counter, and a receive first sets the counter to the larger of its own and the message’s. The value after the event is its timestamp. A vector clock keeps, in each of processes, a vector of counters: before each event, process adds 1 to entry ; a message carries the sender’s vector, and a receive first takes the entrywise maximum of its own and the message’s. is the vector after the event. For vectors, means for every , and means and .
lamport.py: time runs to the right on each process’s line, and each arrow is a message. Each event shows its Lamport timestamp. c1 has the smaller timestamp than a2, yet no chain of messages leads from one to the other.