previous | start | next

Interrupts

A context switch, but not to another thread.

What stack should be used by the interrupt handler code?

Most systems, the interrupt handler borrows the interrupted thread's kernel stack.

If an interrupt handler is interrupted (maybe not always allowed), its context is saved on the current stack, and that stack continues to be used for the new interrupt handler.

If an interrupt handler is interrupted, the new interrupt handler must complete before returning to the previous interrupt handler. This is because these interrupt handlers are using the same stack. The interrupt handlers have no thread context and so don't have their own stack that would allow switching back and forth as described for threads.

If an interrupt handler has some deferred work that can only be done after some later event, it might want to yield to another interrupt handler or thread.

But if it yields, since an interrupt handler has no thread context, it will never be scheduled and so this deferred work will not be executed.

Linux and Windows handle this by creating some sort of queue of deferred work and arrange for this queue to be checked when any thread is scheduled to run.



previous | start | next