
1
CMSC 330: Organization of
Programming Languages
Project 5
CMSC 330 2
Multithreaded Simulation
Goal
•
Implement multithreaded Metro simulation in Ruby
Separate threads for trains, passengers
Monitors to avoid data races
Conditions to efficiently acquire locks
•
Implement simulation verifier in Ruby
Examine log file of simulation
Determine whether simulation output is consistent
CMSC 330 3
Metro Simulation
You are given
•
List of metro lines & stations on each line
•
List of passengers & their stops
You need to simulate
•
One train per metro line
Train goes up & down line, stopping at each station
•
Passengers
Passengers board & leave trains
CMSC 330 4
Metro Simulation
Multithreading
•
One thread per train
•
One thread per passenger
•
Only one train at a metro station at any time
Simulation outputs
•
Train <color> entering <station>
•
Train <color> leaving <station>
•
<Passenger> boarding train <color> at <station>
•
<Passenger> leaving train <color> at <station>
CMSC 330 5
Simulation Verifier
Analyze simulation output for feasibility
•
Trains start at their initial station
•
Trains move forward and backward along their lines
•
Trains enter a station before they leave it
•
2 trains are not at the same station at the same time
•
Passengers follow their path as given in input
•
Passengers only board & leave train when in station
•
Passengers get to where they're going
•
No extra passengers on trains
CMSC 330 6
Simulation Output
Example
•
Train green leaving Fort Totten
•
Train blue entering L'Enfant Plaza
•
Train red entering Fort Totten
•
Train yellow entering Pentagon
•
Paul boarding train yellow at Pentagon
•
Train green entering Gallery Place
•
Train red leaving Fort Totten
•
Train blue leaving L'Enfant Plaza
•
Train yellow leaving Pentagon
•
Train green leaving Gallery Place