fibers: M:1 scheduler core + suspending fiber-task async (B1.5a, B1.4a)

library/modules/std/sched.sx: a generic Fiber + Scheduler over the
proven naked swap_context on guarded mmap stacks --
init/spawn/yield_now/suspend_self/wake/run (B1.5a), then Task($R) +
go/wait/cancel, a truly-suspending nullary-thunk async layer (B1.4a).
go(work) runs a thunk as a real fiber; wait() parks the caller until it
completes. Self-contained in sched.sx (io.sx importing it would
duplicate the _fib_tramp global asm).

Hardened per adversarial review: wake guarded on .suspended (FIFO
corruption), suspend_self/yield_now guard a null current, loud
mmap/mprotect/OOM/deadlock bails, cancel skips not-yet-run work.
Closure-env + heap-Task leaks documented (bounded, default-GPA-invisible).

Examples: 1811 (round-robin), 1812 (suspend/wake + spurious-wake guard),
1813 (async interleave + await-suspend + cancel). Also files issue 0155
(scalar-pointer index panics codegen -- non-blocking, found in review).
This commit is contained in:
agra
2026-06-21 18:44:03 +03:00
parent d3944570b9
commit 8367ad18b1
18 changed files with 729 additions and 0 deletions

View File

@@ -0,0 +1 @@
{ "target": "macos" }

View File

@@ -0,0 +1,4 @@
sequence: 0 1 2 0 1 2 0 1 2
spawned: 3
done: 1 1 1
all done: 3

View File

@@ -0,0 +1 @@
{ "target": "macos" }

View File

@@ -0,0 +1,2 @@
log: 10 20 21 11
suspended-left: 0

View File

@@ -0,0 +1 @@
{ "target": "macos" }

View File

@@ -0,0 +1,2 @@
sequence: 1 2 3 42 100 -99
spawned: 4