std1.0.0-beta-7 SafeC docs

Module sync::task

#include <std/sync/task.h> source

Cooperative Task Scheduler Stackless cooperative multitasking. Tasks yield voluntarily via resume_point.

Structs

Task
TaskScheduler

Traits

TaskRunnerWhat a cooperative scheduler offers to the code driving it: one round, run to completion, and how many tasks are left. TaskScheduler and ThreadSched (thread_bare.h, priority-ordered) both conform, so a driver loop written once against TaskRunner runs either. Spawning isn't part of it: ThreadSched::spawn takes a priority that TaskScheduler::spawn has no place for. (Not called Scheduler: that's kernel/scheduler.h's struct.)

Functions

run_roundsRuns at most max_rounds rounds of s (a bounded run_all, e.g. for a watchdog-fed main loop). Returns the tasks still active afterwards.

Macros

TASK_READYTask states
TASK_RUNNING
TASK_DONE
TASK_MAXWas 64 -- too low for a reactor thread under real concurrent load: once more than TASK_MAX connections are simultaneously in flight on one TaskScheduler, TaskScheduler::spawn() returns -1 and the caller (see std/http/http.sc's http_accept_task_) closes the freshly-accepted fd before reading its pending request bytes, which the kernel turns into a TCP RST to the client. Verified: ab -c 128 against a single http_serve_reactor thread reliably reproduced exactly this ("Connection reset by peer" partway through the run); ab -c 100 (under the old 64) did not. 1024 gives real headroom above realistic load-test/production concurrency; each Task is small (a few pointers/ints), so the resulting per-scheduler array is trivial (~tens of KB, not the old few KB, but still nothing).