"otherThread" (which is now "currentThread")! The original thread is now "sleeping". *** resume: // This is where another contextSwitch() call needs to set PC to when switching context back here. // Return to where otherThread left off. } public method wait(Mutex m, ConditionVariable c) { // Internal spin-lock while other threads on any core are accessing this object's // "held" and "threadQueue", or "readyQueue". while (testAndSet(threadingSystemBusy)) {} // N.B.: "threadingSystemBusy" is now true. // System call to disable interrupts on this core so that threadSleep() doesn't get interrupted by // the thread-switching timer on this core which would call contextSwitchISR(). // Done outside threadSleep() for more efficiency so that this thread will be sleeped // right after going on the condition-variable queue. systemCall_disableInterrupts(); assert m.held; // (Specifically, this thread must be the one holding it.) m.release(); c.waitingThreads.enqueue(currentThread); threadSleep(); // Thread sleeps ... Thread gets woken up from a signal/broadcast. threadingSystemBusy = false; // Must be an atomic assignment. systemCall_enableInterrupts(); // Turn pre-emptive switching back on on this core. // Mesa style: // Context switches may now occur here, making the client caller's predicate false. m.acquire(); } public method signal(ConditionVariable c) { // Internal spin-lock while other threads on any core are accessing this object's // "held" and "threadQueue", or "readyQueue". while (testAndSet(threadingSystemBusy)) {} // N.B.: "threadingSystemBusy" is now true. // System call to disable interrupts on this core so that threadSleep() doesn't get interrupted by // the thread-switching timer on this core which would call contextSwitchISR(). // Done outside threadSleep() for more efficiency so that this thread will be sleeped // right after going on the condition-variable queue. systemCall_disableInterrupts(); if (!c.waitingThreads.isEmpty()) { wokenThread = c.waitingThreads.dequeue(); readyQueue.enqueue(wokenThread); } threadingSystemBusy = false; // Must be an atomic assignment. systemCall_enableInterrupts(); // Turn pre-emptive switching back on on this core. // Mesa style: // The woken thread is not given any priority. } public method broadcast(ConditionVariable c) { // Internal spin-lock while other threads on any core are accessing this object's // "held" and "threadQueue", or "readyQueue". while (testAndSet(threadingSystemBusy)) {} // N.B.: "threadingSystemBusy" is now true. // System call to disable interrupts on this core so that threadSleep() doesn't get interrupted by // the thread-switching timer on this core which would call contextSwitchISR(). // Done outside threadSleep() for more efficiency so that this thread will be sleeped // right after going on the condition-variable queue. systemCall_disableInterrupts(); while (!c.waitingThreads.isEmpty()) { wokenThread = c.waitingThreads.dequeue(); readyQueue.enqueue(wokenThread); }