|
CMSC 838F, Spring 2007Language-Based Techniques for Concurrent and Distributed SoftwareProject 1Note: You are responsible for reading the web forum and making sure to follow any notes or updates posted about the project there. IntroductionIn this project, you will write a simple multi-threaded simulation in Java, and a tool to check that the output is sensible. The SimulationYour program will simulate a building containing a set of elevators, with people entering and exiting the elevators at various times. All the elevators should run in parallel, as should all the people (so the total number of threads in your system should be at least the number of elevators plus the number of people). I should be able to run your simulation with where n is the number of elevators (numbered consecutively starting from 0), f is the number of floors (numbered consecutively from 0), and file is the name of a text file describing the people's behavior. The simulation ends when every person has visited all the floors they wanted to visit. The file should consist of a sequence of lines each of the form where
bill [1; 2; 0] 2 0 bob [2; 1; 0] 2 0would mean that both bill and bob start on floor 0, bill goes to floor 1, waits 2 seconds, then goes to floor 2, waits 2 seconds, and then goes to floor 0 and waits 2 seconds; and bob goes to floors 2, then 1, then 0, waiting 2 seconds upon arriving at each floor. As the people participate in the simulation, they should print out messages to standard output saying what they are doing:
Elevator e should start at floor e mod numFloors, where numFloors is the total number of floors in the building. Each elevator may hold at most 3 people. When an elevator arrives at a floor, it should print where e is the elevator number and f is the floor number. Then the elevator should sleep for 1 second, during which time people may enter or exit the elevator. After the elevator wakes up, it should print An elevator should service every floor it reaches, and the floors must be serviced in order (i.e., after servicing floor 1, the elevator should either service floor 2 or 0 next, depending on its direction.) To keep things simple, we will use the following algorithm to control the elevators: Every elevator will begin moving up, until it has serviced the top (highest-numbered) floor, and then it will switch and move down, until it reaches floor 0, and then switches direction etc. Important note: In Java, the output of multiple threads can be interleaved arbitrarily. To make sure the output trace from your execution makes sense, you should do two things when you print to standard output: First, make sure that you print before releasing a lock (i.e., in the critical section with the action that you are printing a message about); second, be sure to invoke the flush method to flush standard output after each print statement. The VerifierThe other part of this project is to write a program to verify that the output of your simulation makes sense. Because the simulation is non-deterministic, the sequence of events is not guaranteed to be the same on each run, but there are certain invariants that must hold. In particular:
To run your verifier, I will do the following: java Simulation n f file > out.txt verify n f file out.txtwhere verify is the name of your program to verify the output. If the output verifies, your program should print yes, otherwise it should print no, along with a helpful message explaining what failed to verify. Be sure to include a README file telling me how to run your verifier, and make sure I can run it on junkfood. You may write your verifier in any language. I recommend a scripting language with support for regular expressions, but languages like C, Java, or OCaml should also be fine. CollaborationAll of the work on your project should be your own, but for this project only, you may collaborate in the following two ways:
When grading your projects, I intend to use different people's verifiers on different people's output. |