Assignment 2: Trainspotting II

In this assignment, you will implement a variation of the program to control the two trains that uses monitors rather than semaphores.

Placeholder for the map, please enable images

Choice of programming language.

In this assignment you must use Java.

Assignment

Your assignment is to adapt the program that controls the trains from the Assignment 1 to use monitors instead of semaphores.

Requirements

  • All the requirements from the first assignment are also demanded here except that now we use monitors instead of semaphores.
  • You should use monitors that have explicit locks and condition variables . That is, you must use the java.util.concurrent.locks package from Java 5, *not* synchronized methods, to implement your monitor .
  • You should not use the tryLock() method of the Lock interface. If you need such functionality, you have to implement it yourself in your monitor.
  • Waiting in your monitors should be realised using condition variables. Locks should be held locked only for short moments.

Tips and Tricks

  • To give you some hints, you should think that each track is represented by a monitor. The monitor will have, at least , the following interface:
    public void enter() 
    public void leave() 
    
    where enter() is called by a train when entering a single track and leave() when a train leaves a single or double track.

Submission

In your submission, you should clearly explain the following items:
  • What is the purpose of each method in the monitor?
  • How many conditional variables, if any, are needed in your solution? Justify your answer.
Last modified: Tuesday, 20-Aug-2013 16:13:11 CEST
COMPUTER SCIENCE AND ENGINEERING - Chalmers University of Technology and Göteborg University
SE-412 96 Göteborg, Sweden - Tel: +46 (0)31- 772 1000