class Lock { private: int value = FREE; Queue waiting; public: void acquire(); void release(); } Lock::acquire() { TCB *chosenTCB; disableInterrupts(); if (value == BUSY) { waiting.add(runningThread); runningThread->state = #\waitingThreadState#; next = readyList.remove(); thread_switch(runningThread, chosenTCB); runningThread->state = #\runningThreadState#; } else { value = BUSY; } enableInterrupts(); } Lock::release() { // next thread to hold lock TCB *next; disableInterrupts(); if (waiting.notEmpty()) { // move one TCB from waiting // to ready next = waiting.remove(); next->state = #\readyThreadState#; readyList.add(next); } else { value = FREE; } enableInterrupts(); }