Skip to content

Complex RTOS elevator simulation using multi-threading and OOP C++ concepts

Notifications You must be signed in to change notification settings

vrnrn/Elevators

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Elevator Simulation Project

Using multithreading and Real-Time Operating System (RTOS) concepts, this project implements a complex simulation of a building's elevator system. The system demonstrates process management, inter-process communication (IPC), and thread synchronization in C++.

System Architecture

The project is architected as a multi-process system where distinct components run as separate processes, communicating via IPC mechanisms. This design simulates a distributed control system typical of real-world elevator arrays.

The system consists of three main process types:

  1. Dispatcher Process: The central brain.
  2. Elevator Processes: Autonomous controllers for each physical elevator.
  3. IO Process: Interactive visualization and input handler.

Building Blocks

Dispatcher (main.cpp)

The Dispatcher is the parent process responsible for:

  • Process Creation: Spawning the Elevator and IO processes.
  • Algorithm: Implementing the scheduling logic (in algo function) to assign floor requests to the most suitable elevator based on proximity, direction, and idle status.
  • Coordination: Monitoring the state of all elevators and routing commands from the IO system.

Elevators (elevator1.cpp, elevator2.cpp)

Each Elevator runs as an independent process (elevator1.exe, elevator2.exe). They are responsible for:

  • State Management: Tracking current floor, direction, door status, and service mode (fault/no-fault).
  • Movement Logic: Simulating travel between floors, handling door operations, and managing a local queue of destinations.
  • Synchronization: Signaling completion of tasks to the Dispatcher.

IO (io.cpp)

The IO Process handles user interaction and visualization:

  • Visualization: Renders the dynamic ASCII art state of the elevators (position, doors, status) to the console.
  • Input Handling: Captures keyboard commands (manual floor requests, fault injection, passenger simulation) and validates them using Regex.
  • Communication: Pipes validated commands to the Dispatcher.

Key Technologies

The simulation relies heavily on rt.h (a custom RTOS wrapper) to implement advanced system programming concepts:

  • Inter-Process Communication (IPC):

    • Pipelines: Used for streaming user commands from the IO process to the Dispatcher.
    • Mailboxes: Message queues used by the Dispatcher to send commands (e.g., "Go to Floor 5") to specific Elevators.
    • Datapools (Shared Memory): Used for low-latency status sharing between processes.
  • Synchronization:

    • Semaphores: Coordinate producer-consumer relationships (e.g., waiting for new commands).
    • Mutexes: Protect shared resources like the console output to prevent text collision (console mutex).
    • Monitors: Encapsulate shared data and synchronization logic (e.g., the elevator class in elevator.h).
  • Multithreading:

    • Inside the processes, individual threads manage distinct tasks like screen updates, input polling, and logic processing (e.g., e1update, e2update, algo threads in Dispatcher).

Usage

  • Manual Control: Input commands to send elevators to specific floors.
  • Auto Mode: Generates dynamic "passenger" objects that make random requests, testing the scheduler's efficiency.
  • Fault Injection: Can simulate mechanical faults to test error handling and service isolation.

Project done in a pair-programming setting using Visual Studio LiveShare.

About

Complex RTOS elevator simulation using multi-threading and OOP C++ concepts

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages