Concurrent Programming - Course Work 2

The Dining Savages: A tribe of savages eats communal dinners from a large pot that can hold M servings of stewed missionary. When a savage wants to eat, he helps himself from the pot, unless it is empty. If the pot is empty, the savage wakes up the cook and then waits until the cook has refilled the pot. If the pot is empty and there are no savages waiting to eat then the cook does not fill the pot. The behaviour of savages and cook is specified by the following program. . Provide the code for the monitor class PotMonitor.

class Savage implements Runnable {
    PotMonitor pot_;
    public Savage (PotMonitor pot) {pot_= pot;}

    public void run() {
        while(true){
            //scratch stomach  
            pot_.getServing();
            //eat
        }
    }
}

class Cook implements Runnable {
    PotMonitor pot_;
    public Cook (PotMonitor pot) {pot_= pot;}

    public void run() {
      while(true) 
        pot_.fill();
    }
}

class PotMonitor {
   final static int M = 4;
   //declare variables
   public synchronized void fill(int M) {} //implement
   public synchronized void getServing() {} //implement
}

Specify the invariant for PotMonitor.