evaluates to boolean. This itself is a critical // section, so you *MUST* be holding the lock when // executing this "while" loop condition! // If this is not the first time the "while" condition is being checked, // then we are asking the question, "Now that another thread using this // monitor has notified me and woken me up and I have been context-switched // back to, did the condition/predicate/assertion we are waiting on stay // true between the time that I was woken up and the time that I re-acquired // the lock inside the "wait" call in the last iteration of this loop, or // did some other thread cause the condition to become false again in the // meantime thus making this a spurious wakeup? { // If this is the first iteration of the loop, then the answer is // "no" -- the condition is not ready yet. Otherwise, the answer is: // the latter. This was a spurious wakeup, some other thread occurred // first and caused the condition to become false again, and we must // wait again. wait(m, cv); // Temporarily prevent any other thread on any core from doing // operations on m or cv. // release(m) // Atomically release lock "m" so other // // code using this concurrent data // // can operate, move this thread to cv's // // wait-queue so that it will be notified // // sometime when the condition becomes // // true, and sleep this thread. Re-enable // // other threads and cores to do // // operations on m and cv. // // Context switch occurs on this core. // // At some future time, the condition we are waiting for becomes // true, and another thread using this monitor (m, cv) does either // a signal that happens to wake this thread up, or a // broadcast that wakes us up, meaning that we have been taken out // of cv's wait-queue. // // During this time, other threads may cause the condition to // become false again, or the condition may toggle one or more // times, or it may happen to stay true. // // This thread is switched back to on some core. // // acquire(m) // Lock "m" is re-acquired. // End this loop iteration and re-check the "while" loop condition to make // sure the predicate is