Idle Thread

Some operating systems use an idle thread to handle cases in which the ready queue would otherwise become empty. Instead of handling those cases individually, the idle thread is simply scheduled. The idle thread, with some infamous exceptions, then puts the machine in a low-power state until an event (e.g. interrupt) enables another thread to run.

The initial version of EPOS-- you are currently working with implements the idle thread as a function that is called whenever there is no other thread on the ready queue to run, like in the excerpt of the suspend() method reproduced bellow:

1.
2.
3.
4.
if(!_ready.empty())
    switch_threads(old, new);
else
    idle();

The idle() function is shown bellow:

1.
2.
3.
4.
5.
void Thread::idle()
{
    CPU::int_enable();
    CPU::halt();
}

To do

You are requested to modify the implementation of idle so it becomes a thread that is only scheduled when there are no other threads ready to run, thus eliminating bugs like having the timer handler to undesirably waking up a suspended thread.