Skip to main content

Module task

Module task 

Source
Expand description

Task lifecycle types: TaskHeader, Task, JoinHandle.

§Memory Model

Two separate heap allocations per spawned future:

  1. Arc<TaskHeader> — shared between executor (Task), all Wakers, and JoinHandle. Contains the atomic state, vtable pointer, join-waker slot, and the output slot (written on completion, read by JoinHandle).

  2. Box<TaskBody<F>> (stored as body_ptr: *mut () in TaskHeader) — owns the erased Pin<Box<F>> (the live future). Freed by the executor the moment the future resolves or the task is cancelled, independent of when the JoinHandle reads the output.

Separating the output from the body lets drop_body free the future immediately on completion while the output lives safely in the Arc until JoinHandle::poll retrieves it.

Structs§

JoinHandle
Future returned from spawn(). Resolves when the spawned task completes.

Enums§

JoinError
Error returned by a JoinHandle when the task does not complete normally.