989 B
989 B
- The print sem is initialized to 0, because the print needs to first wait for the first simulation tick to happen.
- The simulation sem is initialized to the number of cpus, since each cpu needs to tick once before the print can happen.
- 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.
- The print thread will wait on the sim sem for each CPU thread, and this should leave the sem at 0 again.
- 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.
- Repeat steps 3-5 until the simulation is done.
This is the general process, at least at the time I wrote this down lmao