public class SyncVar<T> {

    private T content = null;

    private Object r = new Object(),
	           w = new Object();

    private boolean reader,writer;

    public SyncVar () {
  	reader = false;
	writer = false;
    }

    public void put (T o) throws InterruptedException {
	synchronized (w) {
	    writer = true;
	    synchronized (this) {
		while (!reader) {
		    this.notify();
		    this.wait();
		};
		reader = false;
		content = o;
	    }
	}
    }

    public T take () throws InterruptedException {
	synchronized (r) {
	    reader = true;
	    synchronized (this) {
		while (!writer) {
		    this.notify();
		    this.wait();
		};
		writer =  false;
		return content;}
	}
    }
}
	