Namespaces
Variants
Views
Actions

std::stop_token

From cppreference.com
< cpp‎ | thread
 
 
Thread support library
Threads
(C++11)
(C++20)
stop_token
(C++20)
this_thread namespace
(C++11)
(C++11)
(C++11)
Mutual exclusion
(C++11)
Generic lock management
(C++11)
(C++11)
(C++11)
(C++11)(C++11)(C++11)
(C++11)
(C++11)
Condition variables
(C++11)
Semaphores
Latches and barriers
(C++20)
(C++20)
Futures
(C++11)
(C++11)
(C++11)
(C++11)
 
 
Defined in header <stop_token>
class stop_token;
(since C++20)

The stop_token class provides the means to check if a stop request has been made or can be made, for its associated std::stop_source object. It is essentially a thread-safe "view" of the associated stop-state.

The stop_token can also be passed to the constructor of std::stop_callback, such that the callback will be invoked if the stop_token's associated std::stop_source is requested to stop. And stop_token can be passed to the interruptible waiting functions of std::condition_variable_any, to interrupt the condition variable's wait if stop is requested.

Contents

[edit] Member functions

constructs new stop_token object
(public member function) [edit]
destructs the stop_token object
(public member function) [edit]
assigns the stop_token object
(public member function) [edit]
Modifiers
swaps two stop_token objects
(public member function) [edit]
Observers
checks whether the associated stop-state has been requested to stop
(public member function) [edit]
checks whether associated stop-state can be requested to stop
(public member function) [edit]

[edit] Non-member functions

compares two std::stop_token objects
(function) [edit]
specializes the std::swap algorithm
(function) [edit]

[edit] Notes

A stop_token object is not generally constructed independently, but rather retrieved from a std::jthread or std::stop_source. This makes it share the same associated stop-state as the std::jthread or std::stop_source.

[edit] Example