标准库头文件 <stop_token> (C++20)
来自 cppreference.com
此头文件是 线程支持 库的一部分。
类 | ||
(C++20) |
用于查询 std::jthread 取消请求是否已发出的接口 (类) | |
(C++20) |
表示请求停止一个或多个 std::jthread 的类 (类) | |
(C++20) |
在 std::jthread 取消时注册回调的接口 (类模板) | |
标签 | ||
(C++20) |
用于 stop_source 的标签,表示在构造时没有关联的停止状态(标签) |
[编辑] 概述
namespace std { // class stop_token class stop_token; // class stop_source class stop_source; // no-shared-stop-state indicator struct nostopstate_t { explicit nostopstate_t() = default; }; inline constexpr nostopstate_t nostopstate{}; // class stop_callback template<class Callback> class stop_callback; }
[编辑] 类 std::stop_token
namespace std { class stop_token { public: // constructors, copy, and assignment stop_token() noexcept; stop_token(const stop_token&) noexcept; stop_token(stop_token&&) noexcept; stop_token& operator=(const stop_token&) noexcept; stop_token& operator=(stop_token&&) noexcept; ~stop_token(); void swap(stop_token&) noexcept; // stop handling bool stop_requested() const noexcept; bool stop_possible() const noexcept; friend bool operator==(const stop_token& lhs, const stop_token& rhs) noexcept; friend void swap(stop_token& lhs, stop_token& rhs) noexcept; }; }
[编辑] 类 std::stop_source
namespace std { // no-shared-stop-state indicator struct nostopstate_t { explicit nostopstate_t() = default; }; inline constexpr nostopstate_t nostopstate{}; class stop_source { public: // constructors, copy, and assignment stop_source(); explicit stop_source(nostopstate_t) noexcept; stop_source(const stop_source&) noexcept; stop_source(stop_source&&) noexcept; stop_source& operator=(const stop_source&) noexcept; stop_source& operator=(stop_source&&) noexcept; ~stop_source(); void swap(stop_source&) noexcept; // stop handling stop_token get_token() const noexcept; bool stop_possible() const noexcept; bool stop_requested() const noexcept; bool request_stop() noexcept; friend bool operator==(const stop_source& lhs, const stop_source& rhs) noexcept; friend void swap(stop_source& lhs, stop_source& rhs) noexcept; }; }
[编辑] 类模板 std::stop_callback
namespace std { template<class Callback> class stop_callback { public: using callback_type = Callback; // constructors and destructor template<class C> explicit stop_callback(const stop_token& st, C&& cb) noexcept(is_nothrow_constructible_v<Callback, C>); template<class C> explicit stop_callback(stop_token&& st, C&& cb) noexcept(is_nothrow_constructible_v<Callback, C>); ~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: Callback callback; // exposition only }; template<class Callback> stop_callback(stop_token, Callback) -> stop_callback<Callback>; }