Timestamp Based Critical Section

Select the number of processes:


Select the speed of the simulation:








How to use the simulator

  1. Select the number of processes that you want to be present in the simulation.
  2. Select the speed of the simulation, this can be changed after starting the animation but you have to click 'Pause/Resume Simulation' after changing from step to fast or slow.
  3. To pause the simulation with fast or slow speeds click on 'Pause/Resume Simulation'.
  4. To reset the simulation, click on 'Reset Simulation'.

About the Algorithm

The purpose of this algorithm is to ensure that distributed processes do not access a shared resource (critical section) at the same time. This is accomplished by making use of Lamport Timestamps to assign every request a time value. Before a process enters the critical section, it waits on acknowledgments from every other process. Once finished, it lets all the other processes know that it is done, and they each remove that request from their queues; then, the next waiting process enters the critical section.

Algorithm pseudocode:
Pi: (initially timestamp = 0)
  on event e:
  case e is send(msg)
   timestamp = timestamp + 1
   msg.timestamp = timestamp
  case e is receive(msg)
   timestamp = max(timstamp, msg.timestamp)
   timstamp = timestamp + 1
  case e is any other event
   timestamp = timestamp + 1
  e.timestamp = timestamp