CS3413/Assignment5/Process.md

989 B

  1. The print sem is initialized to 0, because the print needs to first wait for the first simulation tick to happen.
  2. The simulation sem is initialized to the number of cpus, since each cpu needs to tick once before the print can happen.
  3. The simulation on each cpu is started, and at the end of each simulation, the sim thread will post to the print sem, so the print thread can print the results. The sim thread will now wait for the print sem, since it needs to wait for the print to finish before it can start the next simulation.
  4. The print thread will wait on the sim sem for each CPU thread, and this should leave the sem at 0 again.
  5. At the end of the print function, before the simulation is allowed to print again, the print thread will increase the time, and then post to the sim sem for each CPU thread, so the simulation can start again.
  6. Repeat steps 3-5 until the simulation is done.

This is the general process, at least at the time I wrote this down lmao