Skip to content

akhmadferoz/af06109-os-hw-04

Repository files navigation

CS 232 Operating Systems

Assignment 04: Street Simulation

github

GitHub Repository Link

How To Run This Program

Method 1

In order to compile the program, run the following command:

gcc -Wall -lpthread ./**/*.c -o main.out

Once the program has been compiled, run the following command to execute the compiled program:

./main.out

Explanation

I have made use of one mutex lock mutexStreet to ensure syncronization of the total number of cars (cars_on_street, incoming_onstreet, outgoing_onstreet and cars_since_repair) along with two conditional variables condStreet to monitor street repair and condFLow to monitor the current traffic flow.

Every time a car, incoming or outgoing wishes to enter the street, the incoming_enter and outgoing_enter functions enable the lock and then check if the street is currently being repaired. If it is, the car waits on the condStreet conditional variable. Once the street is repaired, the car is allowed to enter the street and the lock is disabled.

In addition, I check if the street capacity is not exceeded. If it is, the car waits on the condFlow conditional variable again. Once the street capacity is under 3, the car is allowed to enter the street and the lock is disabled.

Finally, I check if the street needs to be repaired based on the total number of cars that have entered the street since the last repair. If it does, the street is repaired and the condStreet conditional variable is signalled to allow the cars waiting on the street to enter.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published