02158  Concurrent Programming - Lab 3: Basic Java Monitors - solution proposal
Technical University of Denmark DTU
02158 Concurrent Programming        Fall 2024
Lab 3: Basic Java Monitors - solution proposal
Home Plan Material  

A: Basic Alley

If we introduce monitor variables counting cars going up and down, the invariant to be maintained is:

  ! (up > 0 && down > 0)

This is ensured by the entry actions:

  < up == 0 -> down++ >
  < down == 0 -> up++ >

which are readily implemented using the standard pattern in BasicAlley.java

B: Double Alley

An extra counter counting upgoing cars in the inner alley may be added. Now cars no. 1 and 2 can enter the alley if only upInner is zero. The result can be found in DoubleAlley.java

C: A Gate Monitor

No solution provided.

Hans Henrik Løvengreen, Oct 31, 2024