Skip to main content

Module task

Module task 

Source
Expand description

Task scopes, task handles, and the task-safety rule at their boundary.

The Language Card states the whole contract this module implements:

Concurrent work belongs to a task scope. Leaving the scope waits for or cancels its child tasks. Immutable task-safe values such as arrays may cross task boundaries. A vector cannot cross, even through let; finish it as an array or wrap mutable state in Shared or another synchronized type. Closures are task-safe only when every capture is.

ADR 0008 runs a spawned task on a thread of its own, so a handle here owns that thread: the body starts when the task is created and the value it produces is reachable only by joining it, which is what await and leaving a scope both do. The state machine still holds no scheduling policy — Tasking below is what decides when a task is joined, and both evaluators reach it — because a value is observable through await or scope exit and through nothing else.

A task’s handle belongs to the thread that spawned it: Task is Rc and its state is a RefCell, because only the spawning task ever touches it. What crosses the boundary is the body on the way in and the value on the way out, both as a Transfer, plus a Cancellation the child observes at its own safepoints.

Structs§

NotTaskSafe
The first value in a capture that may not cross a task boundary.
Task
A spawned unit of work and the value it will produce.
TaskScope
The task scope scope name { ... } binds.
TransferClosure
The parts of a Closure a receiving task can own.

Enums§

TaskState
What a spawned task has done so far.
Transfer
A task-safe value in the form the receiving task can own.

Constants§

TASK_SAFETY_RULE
The Language Card sentence every task-safety diagnostic quotes.

Type Aliases§

TaskOutcome
What a task thread hands back to the task that spawned it: the value the body produced, in the form that may cross the boundary, or why it stopped.