boost::capy::continuation
Pairs a coroutine handle with a scratch slot so executors can queue it without heap allocation.
Synopsis
Declared in <boost/capy/continuation.hpp>
struct continuation;
Description
Wraps a std::coroutine_handle<> with a single pointer‐sized scratch slot so executors can queue continuations without per‐post heap allocation.
Fields
-
h— the coroutine handle to resume. Set by the code that creates or reuses the continuation (typically an I/O awaitable or combinator). Read by the executor when it dequeues the continuation. -
reserved— a pointer‐sized scratch slot. Ordinary users must not touch it. Authors of awaitable algorithms (e.g.async_mutex,async_semaphore) may commandeer it for their own node‐based data structure. They may do so only before the continuation is submitted to an executor. On submission the executor clobbersreservedto link the continuation into its internal queue; the value carries no meaning afterward. Once submitted, the caller must not read or modify the continuation at all.
Ownership and Lifetime
The continuation is owned by the site that embeds it (an I/O awaitable, combinator state, or trampoline promise). The executor borrows it by reference for the duration of the queue residency.
A continuation must have a stable address while it is linked into an executor's queue. It must not be moved, destroyed, or enqueued in more than one queue concurrently.
An author who needs a doubly‐linked (or otherwise richer) structure should hold a continuation as a member. Deriving from it also works, because continuation is an aggregate. Such an author should manage their own links, because reserved is only a single pre‐submission scratch slot. It is no longer available once the continuation is submitted.
Copy and Move
Trivially copyable and movable (aggregate of a handle and a pointer). However, copying or moving a queued continuation produces a second object whose reserved slot is stale — the executor still links the original. Copy and move are safe only when the continuation is not enqueued.
Thread Safety
A single continuation must not be accessed concurrently without external synchronization. In practice, the creating thread sets h and calls executor.post(c); the executor's worker thread later reads h and calls h.resume(). The executor's internal locking provides the necessary synchronization between these two accesses.
See Also
Created with MrDocs