What do I do if no thread is available to run on a context switch (i.e. all threads are blocked)?
This situation could arise if all the threads in the system are blocked on semaphores or waiting for alarms. The clock interrupt mechanism we have given you assumes that there is always a thread running, ready to take the interrupt. This means that you have to create an “idle thread”, which is ready to run if all the other threads are blocked, but does nothing (i.e. runs a function which loops infinitely, or yields infinitely). The idle thread should only run if all other threads are blocked, so it should not go on run queue with all the normal threads, and should never block!