package Exam;

// a one-slot buffer
class Slot {	
	private Object slotVal;	// initially null
	
	public synchronized void put(Object val) {
		while (slotVal != null) {
			try { wait(); }
			catch (InterruptedException e) { }
		}
		slotVal = val;
		notifyAll();
		return;
	}
	
	public synchronized Object get() {
		Object rval;
		while (slotVal == null) {
			try { wait(); }
			catch (InterruptedException e) { }
		}
		rval = slotVal;
		slotVal = null;
		notifyAll();
		return rval;
	}
}
