Note: Changing the synchronization during execution will reset the simulation
The purpose of this algorithm is to ensure updates between processes execute in the order they were sent in. The algorithm accomplishes this by making use of an array of Lamport Timestamps and priority queues within each process. The local time of each process updates according to the highest timestamp attached to an incoming message. When a process receives a message, it broadcasts to all other processes. As a result, the local times propagate across the network. Messages in the priority queue are executed one at a time for all that is less than the current local time.
Pseudocode for sending an update U from process i:
timestamp_array[i]++
broadcast(U, timestamp_array[i])
Pseudocode for process i receiving an update from process j:
timestamp_array[j] = msg_timestamp
queue.enqueue(msg, msg.msg_timestamp)
if msg_timestamp > timestamp_array[i]
timestamp_array[i] = msg_timestamp
broadcast(ack-msg, timestamp_array[i])
end if
Pseudocode for applying updates:
(update, timestamp) = queue.head()
if (for all j, timestamp <= timestamp_array[j]))
queue.dequeue()
apply(update)
end if