void thread_switch( ) {
thread_t NextThread, OldCurrent;
NextThread = dequeue(RunQueue);
OldCurrent = CurrentThread;
CurrentThread = NextThread;
swapcontext(&OldCurrent->context, &NextThread->context);
// We're now in the new thread's context
}
What if there are no runnable threads; i.e., what if the RunQueue is empty?