//@author: j.n.magee 11/12/96

/********************************************************/
//
// The Read Write Monitor Class
//
class ReadWriteVs1 implements ReadWrite {

    private protected int readers =0;
    private protected boolean writing = false;

    synchronized public void acquireRead() {
        while (writing) {
            try{ wait(); } catch(InterruptedException e){}
        }
        ++readers;
      }

    synchronized public void releaseRead() {
        --readers;
        if(readers==0) notify();
    }

    synchronized public void acquireWrite() {
        while (readers>0 || writing) {
            try{ wait(); } catch(InterruptedException e){}
        }
        writing = true;
      }

    synchronized public void releaseWrite() {
        writing = false;
        notifyAll();
    }

 }
