Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for a snapshot of the master branch, built from commit 0bd9e66d9e.
PrevUpHomeNext

spawn (4 of 6 overloads)

Start a new stackful coroutine that executes on a given executor.

template<
    typename Executor,
    typename StackAllocator,
    typename F,
    typename CompletionToken = default_completion_token_t<Executor>>
auto spawn(
    const Executor & ex,
    allocator_arg_t ,
    StackAllocator && stack_allocator,
    F && function,
    CompletionToken && token = default_completion_token_t< Executor >(),
    constraint_t< is_executor< Executor >::value||execution::is_executor< Executor >::value >  = 0);

This function is used to launch a new stackful coroutine using the specified stack allocator.

Parameters

ex

Identifies the executor that will run the stackful coroutine.

stack_allocator

Denotes the allocator to be used to allocate the underlying coroutine's stack. The type must satisfy the stack-allocator concept defined by the Boost.Context library.

function

The coroutine function. The function must be callable the signature:

void function(basic_yield_context<Executor> yield);
token

The completion token that will handle the notification that the coroutine has completed. If the return type R of function is void, the function signature of the completion handler must be:

void handler(std::exception_ptr);

Otherwise, the function signature of the completion handler must be:

void handler(std::exception_ptr, R);
Completion Signature
void(std::exception_ptr, R)

where R is the return type of the function object.

Per-Operation Cancellation

The new thread of execution is created with a cancellation state that supports cancellation_type::terminal values only. To change the cancellation state, call the basic_yield_context member function reset_cancellation_state.


PrevUpHomeNext