Assuming that all threads are either runnable or waiting on a mutex what can you say if there are no threads on the run queue with this version of thread_switch?
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
}