Semaphores: Traffic Sim

Nerdyfying a college course exercise #ConcurrentProgramming #Visualization

Global Variables Semaphores {} = {}
Integers {} = {}
* light must be in {1, 2}
Algorithms

Exercice

En français: Exercice 2. Synchronisation : la circulation (#archivé)


At an intersection, traffic is controlled by traffic lights (also known as "semaphores).

Rules:


Assumptions: For the sake of simplicity, we assume that:

This system can be modeled as a set of parallel processes:


Predefined functions: p(sema), v(sema), sleep(secs), in addition to Traverser's traverse().


Question: Write the Controller, as well as the Traverser1 and Traverser2 procedures to synchronize the system using semaphores.

Gambatte~

Warnings


For more details, check the GitHub page.

Credits