← Back to all projects

Thoth

Preemptive and Collaborative Task Scheduler for an Embedded RTOS

Thoth Drawing

How I imagined process schedulers before diving into Thoth

Motivation

I'm someone who really only learns once I understand what's going on underneath the hood. I think operating systems are the coolest thing ever, so naturally I really wanted to tinker around with what makes them work. As such, Thoth was created as a toy task scheduler that actually runs on baremetal hardware.

Implementation

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:

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 in action

Thoth driving two different blinking LED tasks concurrently