[stopcallback] # 32 Concurrency support library [[thread]](./#thread) ## 32.3 Stop tokens [[thread.stoptoken]](thread.stoptoken#stopcallback) ### 32.3.6 Class template stop_callback [stopcallback] #### [32.3.6.1](#general) General [[stopcallback.general]](stopcallback.general) [1](#general-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L1039) [🔗](#lib:stop_callback_) namespace std {templateclass stop_callback {public:using callback_type = CallbackFn; // [[stopcallback.cons]](#cons "32.3.6.2 Constructors and destructor"), constructors and destructortemplateexplicit stop_callback(const stop_token& st, Initializer&& init)noexcept(is_nothrow_constructible_v); templateexplicit stop_callback(stop_token&& st, Initializer&& init)noexcept(is_nothrow_constructible_v); ~stop_callback(); stop_callback(const stop_callback&) = delete; stop_callback(stop_callback&&) = delete; stop_callback& operator=(const stop_callback&) = delete; stop_callback& operator=(stop_callback&&) = delete; private: CallbackFn *callback-fn*; // *exposition only*}; template stop_callback(stop_token, CallbackFn) -> stop_callback;} [2](#general-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L1071) *Mandates*: stop_callback is instantiated with an argument for the template parameter CallbackFn that satisfies both [invocable](concept.invocable#concept:invocable "18.7.2 Concept invocable [concept.invocable]") and [destructible](concept.destructible#concept:destructible "18.4.10 Concept destructible [concept.destructible]")[.](#general-2.sentence-1) [3](#general-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L1078) *Remarks*: For a type Initializer, if[*stoppable-callback-for*](stoptoken.concepts#concept:stoppable-callback-for "32.3.3 Stop token concepts [stoptoken.concepts]") is satisfied, then[*stoppable-callback-for*](stoptoken.concepts#concept:stoppable-callback-for "32.3.3 Stop token concepts [stoptoken.concepts]") is modeled[.](#general-3.sentence-1) The exposition-only *callback-fn* member is the associated callback function ([[stoptoken.concepts]](stoptoken.concepts "32.3.3 Stop token concepts")) ofstop_callback< CallbackFn> objects[.](#general-3.sentence-2) #### [32.3.6.2](#cons) Constructors and destructor [[stopcallback.cons]](stopcallback.cons) [🔗](#lib:stop_callback,constructor) `template explicit stop_callback(const stop_token& st, Initializer&& init) noexcept(is_nothrow_constructible_v); template explicit stop_callback(stop_token&& st, Initializer&& init) noexcept(is_nothrow_constructible_v); ` [1](#cons-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L1103) *Constraints*: CallbackFn and Initializer satisfy[constructible_from](concept.constructible#concept:constructible_from "18.4.11 Concept constructible_­from [concept.constructible]")[.](#cons-1.sentence-1) [2](#cons-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L1108) *Effects*: Initializes *callback-fn* with std​::​forward(init) and executes a stoppable callback registration ([[stoptoken.concepts]](stoptoken.concepts "32.3.3 Stop token concepts"))[.](#cons-2.sentence-1) If a callback is registered with st's shared stop state, then *this acquires shared ownership of that stop state[.](#cons-2.sentence-2) [🔗](#lib:stop_callback,destructor) `~stop_callback(); ` [3](#cons-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L1122) *Effects*: Executes a stoppable callback deregistration ([[stoptoken.concepts]](stoptoken.concepts "32.3.3 Stop token concepts")) and releases ownership of the stop state, if any[.](#cons-3.sentence-1)