Standard library header <stop_token> (C++20)
From cppreference.net
이 헤더는 스레드 지원 라이브러리의 일부입니다.
클래스 |
||
|
(C++20)
|
std::jthread
취소 요청이 발생했는지 질의하기 위한 인터페이스
(클래스) |
|
|
(C++20)
|
하나 이상의
std::jthread
중단 요청을 나타내는 클래스
(클래스) |
|
|
(C++20)
|
std::jthread
취소 시 콜백을 등록하기 위한 인터페이스
(클래스 템플릿) |
|
|
(C++26)
|
정지가 절대 발생하지 않거나 요청되지 않는 stop token 인터페이스를 제공함
(클래스) |
|
|
(C++26)
|
해당
std::inplace_stop_source
객체의 정지 상태를 참조하는 정지 토큰
(클래스) |
|
|
(C++26)
|
정지 상태의 단독 소유자인
stoppable-source
(클래스) |
|
|
(C++26)
|
std::inplace_stop_token
을 위한 정지 콜백
(클래스 템플릿) |
|
별칭 템플릿 |
||
|
(C++26)
|
주어진 stop 토큰 타입에 대한 콜백 타입을 얻음
(alias template) |
|
Concepts |
||
|
(C++26)
|
정지 요청에 대한 질의와 정지 요청이 가능한지 여부를 허용하는 정지 토큰의 기본 인터페이스를 명시함
(concept) |
|
|
(C++26)
|
중단을 허용하지 않는 스톱 토큰을 명시함
(concept) |
|
태그 |
||
|
(C++20)
|
생성 시 연관된 stop-state 없음을 나타내기 위한
stop_source
태그
(태그) |
|
시놉시스
namespace std { // 정지 토큰 개념들 template<class CallbackFn, class Token, class Init = CallbackFn> concept /*stoppable-callback-for*/ = /* see description */; // 설명 전용 template<class Token> concept stoppable_token = /* see description */; template<class Token> concept unstoppable_token = /* see description */; template<class Source> concept /*stoppable-source*/ = /* see description */; // 설명 전용 // 클래스 stop_token class stop_token; // 클래스 stop_source class stop_source; // 공유되지 않는 정지 상태 표시자 struct nostopstate_t { explicit nostopstate_t() = default; }; inline constexpr nostopstate_t nostopstate{}; // 클래스 템플릿 stop_callback template<class Callback> class stop_callback; // 클래스 never_stop_token class never_stop_token; // 클래스 inplace_stop_token class inplace_stop_token; // 클래스 inplace_stop_source class inplace_stop_source; // 클래스 템플릿 inplace_stop_callback template<class CallbackFn> class inplace_stop_callback; template<class T, class CallbackFn> using stop_callback_for_t = T::template callback_type<CallbackFn>; }
Stop token 개념
namespace std { template<class CallbackFn, class Token, class Init = CallbackFn> concept /*stoppable-callback-for*/ = // 설명용 전용 invocable<CallbackFn> && constructible_from<CallbackFn, Init> && requires { typename stop_callback_for_t<Token, CallbackFn>; } && constructible_from<stop_callback_for_t<Token, CallbackFn>, const Token&, Init>; template<template<class> class> struct /*check-type-alias-exists*/; // 설명용 전용 template<class Token> concept stoppable_token = requires (const Token tok) { typename /*check-type-alias-exists*/<Token::template callback_type>; { tok.stop_requested() } noexcept -> same_as<bool>; { tok.stop_possible() } noexcept -> same_as<bool>; { Token(tok) } noexcept; // 암시적 표현 변형 참조 } && copyable<Token> && equality_comparable<Token>; template<class Token> concept unstoppable_token = stoppable_token<Token> && requires (const Token tok) { requires bool_constant<(!tok.stop_possible())>::value; }; template<class Source> concept /*stoppable-source*/ = // 설명용 전용 requires (Source& src, const Source csrc) { { csrc.get_token() } -> stoppable_token; { csrc.stop_possible() } noexcept -> same_as<bool>; { csrc.stop_requested() } noexcept -> same_as<bool>; { src.request_stop() } -> same_as<bool>; }; }
클래스 std::stop_token
namespace std { class stop_token { public: template<class CallbackFn> using callback_type = stop_callback<CallbackFn>; // 생성자, 복사, 할당 stop_token() noexcept = default; // 멤버 함수 void swap(stop_token&) noexcept; // 정지 처리 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; private: shared_ptr</*unspecified*/> stop_state_; // 설명 전용 }; }
클래스 std::stop_source
namespace std { class stop_source { public: // 생성자, 복사, 할당 stop_source(); explicit stop_source(nostopstate_t) noexcept {} // 멤버 함수 void swap(stop_source&) noexcept; // 정지 처리 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; private: shared_ptr</*unspecified*/> stop_state_; // 설명 전용 }; }
클래스 템플릿 std::stop_callback
namespace std { template<class CallbackFn> class stop_callback { public: using callback_type = CallbackFn; // 생성자 및 소멸자 template<class Init> explicit stop_callback(const stop_token& st, Init&& init) noexcept(is_nothrow_constructible_v<CallbackFn, Init>); template<class Init> explicit stop_callback(stop_token&& st, Init&& init) noexcept(is_nothrow_constructible_v<CallbackFn, Init>); ~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_; // 설명 전용 }; template<class CallbackFn> stop_callback(stop_token, CallbackFn) -> stop_callback<CallbackFn>; }
클래스 템플릿 std::never_stop_token
namespace std { class never_stop_token { struct /*callback-type*/ { // 설명 전용 explicit /*callback-type*/(never_stop_token, auto&&) noexcept {} }; public: template<class> using callback_type = /*callback-type*/; static constexpr bool stop_requested() noexcept { return false; } static constexpr bool stop_posible() noexcept { return false; } bool operator==(const never_stop_token&) const = default; }; }
클래스 템플릿 std::inplace_stop_token
namespace std { class inplace_stop_token { public: template<class CallbackFn> using callback_type = inplace_stop_callback<CallbackFn>; inplace_stop_token() = default; bool operator==(const inplace_stop_token&) const = default; // 멤버 함수 bool stop_requested() const noexcept; bool stop_possible() const noexcept; void swap(inplace_stop_token&) noexcept; private: const inplace_stop_source* stop_source_ = nullptr; // 설명 전용 }; }
클래스 템플릿 std::inplace_stop_source
namespace std { class inplace_stop_source { // 생성자, 할당 연산자, 소멸자 constexpr inplace_stop_source() noexcept; inplace_stop_source(inplace_stop_source&&) = delete; inplace_stop_source(const inplace_stop_source&) = delete; inplace_stop_source& operator=(inplace_stop_source&&) = delete; inplace_stop_source& operator=(const inplace_stop_source&) = delete; ~inplace_stop_source(); // 정지 처리 constexpr inplace_stop_token get_token() const noexcept; static constexpr bool stop_possible() noexcept { return true; } bool stop_requested() const noexcept; bool request_stop() noexcept; }; }
클래스 템플릿 std::inplace_stop_callback
namespace std { template<class CallbackFn> class inplace_stop_callback { public: using callback_type = CallbackFn; // 생성자 및 소멸자 template<class Init> explicit inplace_stop_callback(inplace_stop_token st, Init&& init) noexcept(is_nothrow_constructible_v<CallbackFn, Init>); ~inplace_stop_callback(); inplace_stop_callback(const inplace_stop_callback&) = delete; inplace_stop_callback(inplace_stop_callback&&) = delete; inplace_stop_callback& operator=(const inplace_stop_callback&) = delete; inplace_stop_callback& operator=(inplace_stop_callback&&) = delete; private: CallbackFn callback_fn_; // 설명 전용 }; template<class CallbackFn> inplace_stop_callback(inplace_stop_token, CallbackFn) -> inplace_stop_callback<CallbackFn>; }