chrone
chrone is a preemptive, round-robin scheduler. tasks do not yield, the timer takes the CPU from them. the runnable tasks form a ring, and each runs for one timer tick, about ten milliseconds, before the next one gets the CPU.
how a switch happens
when the timer fires, the CPU pushes the interrupted task's return frame onto that task's own stack, and the kernel's interrupt entry pushes the rest of the registers after it. to switch, chrone remembers where that stack pointer ended up, picks the next runnable task in the table and returns from the interrupt on that task's saved stack pointer instead. a new task gets a hand-built frame on a fresh stack that looks as if it had already been interrupted once, so first launch and every later resume take the same path.
tasks live in a fixed-size table of parallel arrays indexed by task id, holding the saved stack pointer, the state, the page table root and, for a ring-3 program with a kakel window, the id of that window.
spawn, exit, kill
task_spawn claims a free slot, gives it a stack and marks it runnable.
task_exit marks the caller's own slot exited. the shell's
kill, closing a tavla and a fault in a ring-3 program mark another
task's slot exited, and the scheduler never picks it again. an exited task cannot
free the stack it is standing on, so a reaper at the top of every tick gives what
other exited tasks owned back to
jenna, a ring-3 program's whole
address space included.
the quantum
the quantum is one tick because of what a longer one does to anything that moves on screen. with four tasks and a quantum of a tenth of a second, a program draws for a tenth of a second and then sits frozen for three tenths. the frame rate is the same either way, only the spacing changes, and at one tick per turn the frames arrive evenly.