[[
wikihub
]]
Search
⌘K
Explore
People
For Agents
Sign in
Explore
People
For Agents
Sign in
@jemoka / Jemoka Knowledge Base / raw/concept/kbhpreemption.md
Suggest edit
Cancel
Submit suggestion
Title
Name
Note
--- title: "preemption" source: https://www.jemoka.com/posts/kbhpreemption/ --- 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 context_switch(...); /* enables interupts, automatically by timer handler */ } void threadfunc_wrapper() { // manually enable interrupts before first run intr_enable(true); // start thread's actual business threadfunc(); }