//
public class SharedBuffer {
    private long val = 0;
    private boolean PresentFlag = false;

    public synchronized long consume(){
	while (!PresentFlag){
	    try{ 
	
	    	wait();
	    	
	    }catch(InterruptedException e){}
	}
	PresentFlag = false;
	
	notifyAll();
	
	return val;
    }
    
    
    public synchronized void produce(long x){
	while (PresentFlag){
	    try{
		wait();
	    }catch(InterruptedException e){}
	}
	val = x;  
	PresentFlag = true;
	
	notifyAll();
	
    }
}
