Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Task

Source: lib/task.x

Guide: Contexts and Threads

Cooperative Channel jobs on dedicated stacks.

Primary API

FunctionSummary
Task.runRuns zero-argument jobs cooperatively on the calling thread.

Task

Task.run

void Task.run(Array jobs, Func completed)

Runs zero-argument jobs cooperatively on the calling thread. Channel waits park a job. The optional completed callback receives each successful result after job cleanup, under restored caller state, and must not wait for participant progress. Results retain ordinary owners. Jobs borrow the caller’s active Scope and Pool until Task.run returns. Each job starts without a current Context and copies the caller’s effective Error policies and limit on accumulated errors. Lisp callback and recursive rendering activations start fresh. Every exit finishes all jobs; failure stops unfinished participants. Thread.stop on the owner requests cooperative batch cancellation. Cleanup bodies must not suspend. Blocking native calls block all jobs. X2C_TASK_STACK_BYTES selects usable capacity before the call; the default is 8 MiB, rounded up to a native page on native builds. No job migrates between threads.

Raises: bad-state for nested execution or an unsupported target, bad-arg for invalid capacity/jobs, allocation/setup causes, join-fail for escaping job Errors, or completion-callback and owner-stop causes.

Source: lib/task.x

Runtime-internal callables

These callables connect runtime translation units. They are documented for source readers but are not supported as user API.

FunctionSummary
x2c_task_channel_notifyWakes parked task waiters while the Channel monitor is locked.
x2c_task_channel_sleepParks the current task and returns with its Channel monitor locked.
x2c_task_currentReturns the current borrowed task token, or NULL on native execution.
x2c_task_stoppingReads a task’s queue-ordered cooperative stop request.

x2c_task_channel_notify

void x2c_task_channel_notify(X2CChannelMonitor *monitor)

Wakes parked task waiters while the Channel monitor is locked.

Source: lib/task.x

x2c_task_channel_sleep

void x2c_task_channel_sleep(X2CChannelMonitor *monitor, Thread *owner)

Parks the current task and returns with its Channel monitor locked. Channel’s mutex protects this stack-local registration and stop/commit. Unregister native Thread before parking, then register again on resume.

Source: lib/task.x

x2c_task_current

void *x2c_task_current(void)

Returns the current borrowed task token, or NULL on native execution.

Source: lib/task.x

x2c_task_stopping

int x2c_task_stopping(void *value)

Reads a task’s queue-ordered cooperative stop request.

Source: lib/task.x

Public types

TypeKindSummary
TaskstructNamespace for cooperative job batches; no public task handles exist.

Task

typedef struct Task *Task

Namespace for cooperative job batches; no public task handles exist.

Source: lib/task.x

Examples