Giter VIP home page Giter VIP logo

cpsc_380_project_3's Introduction

Assignment 2: See-Saw Simulator

1. IDENTIFYING INFO

  • Curren Taber & Joan Karstrom
  • Professor Hansen
  • CPSC 380-01: Operating Systems
  • April 19, 2021

2. SOURCE FILES

  • README.md
  • Main.cpp
  • SeeSaw.h
  • SeeSaw.cpp

3. DESCRIPTION

When Main.cpp runs, it creates a SeeSaw pointer and calls RunSimulation() on the new SeeSaw object. Upon creation, the SeeSaw object initializes two binary semaphores (semFred and semWilma), a boolean (fredsTurn), two doubles for height (fredsHeight and wilmasHeight), and an integer for tracking the current round (i). The RunSimulation() method starts by unlinking and creating the two semaphores, with semFred set to 0 and semWilma set to 1 (this allows Fred to run first since he calls sem_wait() on semWilma). Then, RunSimulation creates two child threads named tid_fred and tid_wilma, which run the functions FredSee() and WilmaSaw(), respectively. Both FredSee() and WilmaSaw() call sem_wait() on the opposite person’s semaphore, execute the critical section, then call sem_post() on their own semaphore. In the critical section, each thread checks if fredsHeight is 1 and wilmasHeight is 7, or vice versa. If this condition occurs, then the fredsTurn changes its value and indicates the current person pushing the see-saw (fredsTurn = true means Fred pushes the see-saw). Fred pushes with an upward velocity of 1 ft/s, whereas Wilma pushes with an upward velocity of 1.5 ft/s. FredSee() and WilmaSaw update the heights of Fred and Wilma, printing their current height every second. Once the simulation finishes ITERATION_COUNT rounds, then tid_fred and tid_wilma join with their parent thread, and the program finishes.

3. REFERENCES

cpsc_380_project_3's People

Contributors

currenluna avatar

Watchers

 avatar  avatar

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.