From 34af9e752788374f8aa342cb066f98158a763cd4 Mon Sep 17 00:00:00 2001 From: Brychan Dempsey Date: Tue, 4 May 2021 11:37:36 +1200 Subject: [PATCH] Renamed logic.md and turned it into documentation --- .gitignore | 1 + details.md | 17 +++++++++++++++++ logic.md | 41 ----------------------------------------- 3 files changed, 18 insertions(+), 41 deletions(-) create mode 100644 details.md delete mode 100644 logic.md diff --git a/.gitignore b/.gitignore index 3ef2bc6..923ee9d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ assignment2.exe assignment2 +assignment2.zip diff --git a/details.md b/details.md new file mode 100644 index 0000000..ec8fdab --- /dev/null +++ b/details.md @@ -0,0 +1,17 @@ +# Lift Simulator +## Implementation Details: +### Added Semaphores: +1. **Print statement wrapped in a semaphore**, to control printing to the console. +(There is a possibility that the console print position could be changed if the currently printing thread was interrupted) + +2. Added a `queueInteraction` semaphore to the `floor_info` struct. The idea of this is that only one lift-call button can be pressed at a time; this prevents more than one person in the queue interacting with the lift. +3. `addToStop` added to the `lift_thread` - this semaphore communicates if the lift is currently adding someone. Used primarily to prevent the lift moving while still loading someone (which would cause an non-loaded person to be unloaded). Very unlikely that this would occur, due to the number of statements that need executing first, but still could potentially occur +4. `targetLiftSelect` allows a lift to set itself as the target lift on a specific floor for a person thread. The person thread releases this semaphore when they load. + +### Added Variables: +1. `targetLift[]` added to keep track of the currently set target lift for a floor. Used in conjunction with semaphore `4`. + +### Other Changes: +1. Added a `POPULATION` preprocessor definition that will print the current counts of people on each floor, and the current floor positions of all people threads. Useful for detecting if someone is stuck. + +2. Changed the speed settings to allow a wider range of debug values diff --git a/logic.md b/logic.md deleted file mode 100644 index e83306f..0000000 --- a/logic.md +++ /dev/null @@ -1,41 +0,0 @@ -# Logic -## Details: -***Stylised text in green represents the actual lift metaphor*** - -***Red represents significant changes to the program*** -## Initial State: -* Lifts all at the bottom of the building -* People all outside the building - * not waiting on an arrow - * not in a lift - -## Loop: -### *These are performed simulataneously, with a thread for each instance* ---- -* ### Lift Thread - *this is a black-box as far as the metaphor goes* - 1. While there are people to unload at this floor, unload them - 2. Call `get_into_lift(Lift, Direction)`, to load people from the apporopriate waiting queue (up | down) from the current floor - 3. Redraw - 3. Change position -* `get_into_lift()` - 1. Fetch the correct semaphor for our queue - 2. Get the number of waiting people on that queue - 3. While there are people waiting: - 1. If the lift is empty, change our direction to the supplied direction - * A semaphore is used before the conditional to help ensure the correct value of `in progress` transfers is correct - 2. While the lift is not full, and we have people waiting: - * Keep track of the number of `in progress` waiting people - 1. Add a person to the lift. - 2. Redraw the waiting queue - 3. Remove the person from the waiting queue - 4. Signal person to actually get into the lift - ---- -* ### Person Thread - *this is modelled around the actual metaphor* - 1. Choose a floor to enter - 2. Decide if the floor is above or below the current position - 3. Add ourselves to the appropriate move (up | down) group Press the `call elevator` button - 4. Wait for the lift to arrive *on the appropriate spot (up | down); no metaphor for this concept* - 5. Enter the lift that is waiting - 6. Move to the waiting group for the target floor Press the target floor button - 7. Wait until the lift reaches our destination floor and leave when it is our turn to exit. \ No newline at end of file