Expand description
Task lifecycle types: TaskHeader, Task, JoinHandle.
§Memory Model
Two separate heap allocations per spawned future:
-
Arc<TaskHeader>— shared between executor (Task), allWakers, andJoinHandle. Contains the atomic state, vtable pointer, join-waker slot, and the output slot (written on completion, read by JoinHandle). -
Box<TaskBody<F>>(stored asbody_ptr: *mut ()inTaskHeader) — owns the erasedPin<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.
§Thread Safety for Multi-Threaded Executor
join_waker is now protected by a Mutex to allow safe concurrent access
between JoinHandle::poll (any worker thread) and poll_task / cancel
(any background worker). The double-check pattern in JoinHandle::poll
ensures the waker is never missed if a task completes concurrently.
Structs§
- Join
Handle - Future returned from
spawn(). Resolves when the spawned task completes.
Enums§
- Join
Error - Error returned by a
JoinHandlewhen the task does not complete normally.