boost::capy::ExecutionContext

Concept for types that provide a place where work is executed.

Synopsis

template<class X>
concept ExecutionContext = std::derived_from<X, execution_context> &&
    requires(X& x) {
        typename X::executor_type;
        requires Executor<typename X::executor_type>;
        { x.get_executor() } noexcept ‐> std::same_as<typename X::executor_type>;
    };

Description

An execution context owns the resources (threads, event loops, completion ports) needed to execute function objects. It serves as the factory for executors, which are lightweight handles used to submit work. Multiple executors may reference the same context.

Syntactic Requirements

  • `X` must be publicly derived from `execution_context`

  • `X::executor_type` must be a type satisfying Executor

  • `x.get_executor()` must return `X::executor_type` and be `noexcept`

Semantic Requirements

The execution context owns the execution environment:

  • Work submitted via any executor from this context runs on resources owned by the context

  • The context remains valid while any executor referencing it exists and may be used

  • Destroying the context destroys all unexecuted work submitted via associated executors

Conforming Signatures

class X : public execution_context
{
public:
    using executor_type = // Executor
    executor_type get_executor() noexcept;
};

Example

template<ExecutionContext Ctx>
void spawn_work( Ctx& ctx )
{
    auto ex = ctx.get_executor();
    ex.post( []{ } ); // work runs on ctx
}

Template Parameters

Name Description

X

The execution context type.

See Also

Executor, execution_context

Created with MrDocs