//Implementation of Alley class with inner alley //CP Lab 3 //Course 02158 Concurrent Programming, DTU //Hans Henrik Lovengreen public class DoubleAlley extends Alley { int up = 0, upInner = 0, down = 0; DoubleAlley() { } @Override /* Block until car no. may enter alley */ public synchronized void enter(int no) throws InterruptedException { if (no < 3) { while (upInner > 0) { wait(); } down++; } else if (no < 5) { while (up > 0) { wait(); } down++; } else { while (down > 0) { wait(); } up++; upInner++; } } @Override /* Register that car no. has left the alley */ public synchronized void leave(int no) { if (no < 5) { down--; if (down == 0) notifyAll(); } else { up--; if (up == 0) notifyAll(); } } @Override /* Register that car no. has left the inner alley */ public synchronized void leaveInner(int no) { upInner--; if (upInner == 0) notifyAll(); } }