sclass Flag is Runnable { private volatile boolean up; /** returns true if flag was down before (i.e. flag was actually raised right now) */ public bool raise() { if (up) false; synchronized { if (up) false; up = true; notifyAll(); true; } } run { raise(); } public void waitUntilUp() ctex { if (up) ret; synchronized { while (!up) wait(); } } public bool waitUntilUp(double timeout) { if (timeout == infinity()) { waitUntilUp(); ret isUp(); } else ret waitUntilUp(toMS(timeout)); } public bool waitUntilUp(long timeout) ctex { if (up) ret true; synchronized { if (!up) wait(timeout); } ret isUp(); } public bool isUp aka get() { ret up; } toString { ret isUp() ? "up" : "down"; } }