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 simply gets 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 didactic version of OpenEPOS 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

Modify the implementation of idle so it becomes a thread that is only scheduled when there are no other threads ready to run. This will eliminate bugs such as having the timer handler undesirably waking up suspended threads.