Runtime Overview
Design documentation for the Run language runtime library (librunrt).
Documents
Section titled “Documents”| Document | Description |
|---|---|
| Architecture | Runtime component diagram, initialization sequence, how generated C code interacts with the runtime |
| Memory | Generational allocation, virtual memory abstraction, slab allocator, arena allocator, custom allocator interface |
| Scheduler | Green thread scheduler based on Go’s GMP model — goroutine/machine/processor design |
| Concurrency | Channels (buffered and unbuffered), synchronization primitives, scheduler integration |
| Platform | Platform-specific details for Linux, macOS, and Windows — virtual memory, threads, signals, context switching |
Overview
Section titled “Overview”The Run runtime provides:
- Memory safety via generational references — every heap allocation carries a generation counter that is incremented on free, and every dereference checks the generation matches
- Green threads — lightweight user-space threads (called “run routines”) scheduled cooperatively across OS threads, inspired by Go’s goroutine model
- Channels — typed communication channels for inter-thread messaging, integrated with the scheduler for efficient blocking/waking
- Strings and slices — built-in dynamic data structures with bounds checking
Implementation Phases
Section titled “Implementation Phases”Phase 1 — Minimal Working Scheduler: Single-threaded cooperative scheduler with fixed-size stacks, context switching via platform assembly, and unbuffered channels.
Phase 2 — Multi-threaded Scheduler: Multiple OS threads, work-stealing, syscall-aware scheduling, cooperative preemption at function prologues.
Phase 3 — Production Hardening: Virtual-memory-backed slab allocator, arena allocator, stack growth, signal-based preemption, buffered channels, Windows support.