Houjun Liu


We use interrupts to implement preemption, “preempting” threads in order to swap on another thread to CPU. This enables scheduling to happen.

preempting into a brand new thread

IMPORTANT: because interrupts are disabled at the beginning of the interrupt handler, and re-enabled by the end, new threads (which starts not at the interrupt handle) will not re-enable interrupts.

void interrupt_handler() {
    /* disables interupts, automatically by timer handler */

    // future spawns start here

    /* enables interupts, automatically by timer handler */

void threadfunc_wrapper() {
    // manually enable interrupts before first run
    // start thread's actual business