SharedObject::someMethodThatWaits() { lock.acquire(); // Read and/or write shared state here. while (!testOnSharedState()) { cv.wait(&lock); } assert(testOnSharedState()); // Read and/or write shared state here. lock.release(); } SharedObject::someMethodThatSignals() { lock.acquire(); // Read and/or write shared state here. // If state has changed in a way that // could allow another thread to make // progress, signal (or broadcast). cv.signal(); lock.release(); }