class CV { private: Queue waiting; public: void wait(Lock *lock); void signal(); void broadcast(); } // Monitor lock is held by current thread. void CV::wait(Lock *lock) { assert(lock.isHeld()); waiting.add(myTCB); // Switch to new thread and release lock. scheduler.suspend(&lock); lock->acquire(); } // Monitor lock is held by current thread. void CV::signal() { if (waiting.notEmpty()) { thread = waiting.remove(); scheduler.makeReady(thread); } } void CV::broadcast() { while (waiting.notEmpty()) { thread = waiting.remove(); scheduler.makeReady(thread); } }