Giter Club home page Giter Club logo

af06109-os-hw-04's Introduction

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.