[exec.task.scheduler] # 33 Execution control library [[exec]](./#exec) ## 33.13 Coroutine utilities [[exec.coro.util]](exec.coro.util#exec.task.scheduler) ### 33.13.5 execution​::​task_scheduler [exec.task.scheduler] namespace std::execution {class [task_scheduler](#lib:task_scheduler "33.13.5 execution​::​task_­scheduler [exec.task.scheduler]") {class *ts-sender*; // *exposition only*template<[receiver](exec.recv.concepts#concept:receiver "33.7.1 Receiver concepts [exec.recv.concepts]") R>class *state*; // *exposition only*public:using scheduler_concept = scheduler_t; template>requires (![same_as](concept.same#concept:same_as "18.4.2 Concept same_­as [concept.same]")>)&& [scheduler](exec.sched#concept:scheduler "33.6 Schedulers [exec.sched]")explicit task_scheduler(Sch&& sch, Allocator alloc = {}); *ts-sender* schedule(); friend bool operator==(const task_scheduler& lhs, const task_scheduler& rhs)noexcept; templaterequires (![same_as](concept.same#concept:same_as "18.4.2 Concept same_­as [concept.same]"))&& [scheduler](exec.sched#concept:scheduler "33.6 Schedulers [exec.sched]")friend bool operator==(const task_scheduler& lhs, const Sch& rhs) noexcept; private: shared_ptr *sch_*; // *exposition only*};} [1](#1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L7028) task_scheduler is a class that models[scheduler](exec.sched#concept:scheduler "33.6 Schedulers [exec.sched]") ([[exec.sched]](exec.sched "33.6 Schedulers"))[.](#1.sentence-1) Given an object s of type task_scheduler, let*SCHED*(s) be the object owned by s.*sch_*[.](#1.sentence-2) [🔗](#lib:task_scheduler,constructor) `template> requires(![same_as](concept.same#concept:same_as "18.4.2 Concept same_­as [concept.same]")>) && [scheduler](exec.sched#concept:scheduler "33.6 Schedulers [exec.sched]") explicit task_scheduler(Sch&& sch, Allocator alloc = {}); ` [2](#2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L7041) *Effects*: Initialize *sch_* withallocate_shared>(alloc,​ std​::​forward​(sch))[.](#2.sentence-1) [3](#3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L7046) *Recommended practice*: Implementations should avoid the use of dynamically allocated memory for small scheduler objects[.](#3.sentence-1) [4](#4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L7051) *Remarks*: Any allocations performed by construction of *ts-sender* or*state* objects resulting from calls on *this are performed using a copy of alloc[.](#4.sentence-1) [🔗](#lib:scheduler,task_scheduler) `ts-sender schedule(); ` [5](#5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L7063) *Effects*: Returns an object of type *ts-sender* containing a sender initialized with schedule(​*SCHED*​(*this))[.](#5.sentence-1) [🔗](#lib:operator==,task_scheduler) `bool operator==(const task_scheduler& lhs, const task_scheduler& rhs) noexcept; ` [6](#6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L7074) *Effects*: Equivalent to: return lhs == *SCHED*(rhs); [🔗](#lib:operator==,task_scheduler_) `template requires (![same_as](concept.same#concept:same_as "18.4.2 Concept same_­as [concept.same]")) && [scheduler](exec.sched#concept:scheduler "33.6 Schedulers [exec.sched]") bool operator==(const task_scheduler& lhs, const Sch& rhs) noexcept; ` [7](#7) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L7087) *Returns*: false if the type of *SCHED*(lhs) is not Sch, otherwise *SCHED*(lhs) == rhs[.](#7.sentence-1) [8](#8) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L7093) namespace std::execution {class task_scheduler::*ts-sender* { // *exposition only*public:using sender_concept = sender_t; template<[receiver](exec.recv.concepts#concept:receiver "33.7.1 Receiver concepts [exec.recv.concepts]") Rcvr>*state* connect(Rcvr&& rcvr); };}*ts-sender* is an exposition-only class that models[sender](exec.snd.concepts#concept:sender "33.9.3 Sender concepts [exec.snd.concepts]") ([[exec.snd]](exec.snd "33.9 Senders")) and for whichcompletion_signatures_of_t<*ts-sender*> denotes:completion_signatures< set_value_t(), set_error_t(error_code), set_error_t(exception_ptr), set_stopped_t()> [9](#9) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L7116) Let *sch* be an object of type task_scheduler and let sndr be an object of type *ts-sender* obtained from schedule(*sch*)[.](#9.sentence-1) Then get_completion_scheduler(get_env(sndr)) == *sch* is true[.](#9.sentence-2) The object *SENDER*(sndr) is the sender object contained bysndr or an object move constructed from it[.](#9.sentence-3) [🔗](#lib:connect,task_scheduler::ts-sender) `template<[receiver](exec.recv.concepts#concept:receiver "33.7.1 Receiver concepts [exec.recv.concepts]") Rcvr> state connect(Rcvr&& rcvr); ` [10](#10) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L7131) *Effects*: Let *r* be an object of a type that models [receiver](exec.recv.concepts#concept:receiver "33.7.1 Receiver concepts [exec.recv.concepts]") and whose completion handlers result in invoking the corresponding completion handlers of rcvr or copy thereof[.](#10.sentence-1) Returns an object of type *state* containing an operation state object initialized with connect(*SENDER*(*this), std​::​move(*r*))[.](#10.sentence-2) [11](#11) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L7141) namespace std::execution {template<[receiver](exec.recv.concepts#concept:receiver "33.7.1 Receiver concepts [exec.recv.concepts]") R>class task_scheduler::*state* { // *exposition only*public:using operation_state_concept = operation_state_t; void start() & noexcept; };}*state* is an exposition-only class template whose specializations model [operation_state](exec.opstate.general#concept:operation_state "33.8.1 General [exec.opstate.general]") ([[exec.opstate]](exec.opstate "33.8 Operation states"))[.](#11.sentence-1) [🔗](#lib:start,task_scheduler::state) `void start() & noexcept; ` [12](#12) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L7161) *Effects*: Equivalent to start(st) where st is the operation state object contained by *this[.](#12.sentence-1)