persistable sclass BoolVar { bool a; // you can access this directly if you use one thread *() {} *(bool *a) {} public synchronized void set(bool v default true) { if (v != a) { a = v; notifyAll(); } } public synchronized bool get() { ret a; } //public synchronized bool has() { true; } public void clear aka unset() { set(false); } bool waitUntilTrue () { ret waitForValue(true); } bool waitUntilFalse() { ret waitForValue(false); } bool waitUntilTrue (double timeoutSeconds) { ret waitForValue(timeoutSeconds, true); } bool waitUntilFalse(double timeoutSeconds) { ret waitForValue(timeoutSeconds, false); } synchronized bool waitForValue(bool wantedValue) ctex { while (a != wantedValue) wait(); ret a; } synchronized bool waitForValue(double timeoutSeconds, bool wantedValue) ctex { if (timeoutSeconds == infinity()) ret waitForValue(wantedValue); long destTime = sysNowPlusSeconds_noPing(timeoutSeconds), remainingTime; while (a != wantedValue && (remainingTime = destTime-sysNow_noPing()) > 0) wait(remainingTime); ret a; } public synchronized bool getAndSet(bool b) { var value = a; set(b); ret value; } public synchronized bool waitUntilTrueAndClear() { if (!waitUntilTrue()) false; set(false); true; } public synchronized bool waitUntilTrueAndClear(double timeoutSeconds) { if (!waitUntilTrue(timeoutSeconds)) false; set(false); true; } O mutex() { this; } }