std::execution::scheduler
Defined in header <execution>
|
||
template<class Sch> concept scheduler = |
(since C++26) | |
The concept scheduler
is modeled by types that are schedulers, that is, lightweight handlers to execution resources such as thread pools that work with the C++ execution library.
Semantic requirements
Given a scheduler of type Sch
and execution environment of type Env
such that sender_in<schedule_result_t<Sch>, Env> is satisfied, then /*sender-in-of*/<schedule_result_t<Sch>, Env> is modeled.
The scheduler's copy constructor, destructor, equality comparison, or swap member functions must be non-throwing.
All of those member functions as well as the scheduler type's schedule
function must be thread-safe.
Two schedulers are equal only if they represent the same execution resource.
For a given scheduler sch
, the expression get_completion_scheduler<set_value_t>(get_env(schedule(sch))) compares equal to sch
.
For a given scheduler sch
, if the expression get_domain(sch) is well-formed, then the expression get_domain(get_env(schedule(sch))) is also well-formed and has the same type.
The destructor of a scheduler must not block pending completion of any receivers connected to the sender objects returned from schedule (the underlying resource may provide a separate API to wait for completion of submitted function objects)
Examples
simple wrapper for std::execution::run_loop
#include <execution> #include <thread> class single_thread_context { std::execution::run_loop loop_; std::thread thread_; public: single_thread_context() : loop_() , thread_([this] { loop_.run(); }) {} single_thread_context(single_thread_context&&) = delete; ~single_thread_context() { loop_.finish(); thread_.join(); } auto get_scheduler() noexcept { return loop_.get_scheduler(); } std::thread::id get_thread_id() const noexcept { return thread_.get_id(); } }; int main() { // TODO }
See also
(C++26) |
prepares a task graph for execution on a given scheduler (customization point object) |