The scheduler implements both preemptive and cooperative multitasking models. Tasks are registered as concurrent processes with configurable priorities and stack sizes.
Thoth was also created with modularity and runtime efficiency in mind. Being used at every context switch, it is super important that the time spent in scheduler-land is very very limited. Thanks to Zig's powerful compile time system, backend assembly and even generic scheduling algorithm choices are all determined at compile time, allowing for powerful interfaces without the need for runtime vtables
Key implementation details:
- Modular compile-time scheduling algorithm selection
- Architecture-agnostic design with architecture-specific context switching
- Efficient context switching using minimal assembly code
- Support for both round-robin and priority-based scheduling
- Memory protection through stack boundary checking
The system includes a yield() function that performs proper context switching based on the selected scheduling algorithm. The modular backend allows different context switching assembly logic for different CPU architectures, determined at compile time.
Thoth driving two different blinking LED tasks concurrently