Concurrent Programming - Course Work 3

A student studying anthropology and computer science has embarked on a research project to see if baboons can be taught about deadlock. He locates a deep canyon and fastens a rope across it, so the baboons can cross hand-over-hand. Several baboons can cross at the same time, provided that they are all going in the same direction. If baboons starting from the South (Southern baboons) and baboons starting from the north (Northern baboons) ever get onto the rope at the same time the baboons will get stuck in the middle.

Below is the outline of the monitor class Rope, used to synchronise access to the rope bridge.

class Rope {
         public synchronized void Sarrive() {} 
         // called by Southern baboons arriving at the South end of the rope 
  1. Complete the implementation of class Rope.
  2. What is the monitor invariant.
  3. Does your solution permit starvation? If so how?