32 Thread support library [thread]

32.3 Stop tokens [thread.stoptoken]

32.3.4 Class stop_­source [stopsource]

32.3.4.2 Members [stopsource.mem]

[[nodiscard]] stop_token get_token() const noexcept;
Returns: stop_­token() if stop_­possible() is false; otherwise a new associated stop_­token object.
[[nodiscard]] bool stop_possible() const noexcept;
Returns: true if *this has ownership of a stop state; otherwise, false.
[[nodiscard]] bool stop_requested() const noexcept;
Returns: true if *this has ownership of a stop state that has received a stop request; otherwise, false.
bool request_stop() noexcept;
Effects: If *this does not have ownership of a stop state, returns false.
Otherwise, atomically determines whether the owned stop state has received a stop request, and if not, makes a stop request.
The determination and making of the stop request are an atomic read-modify-write operation ([intro.races]).
If the request was made, the callbacks registered by associated stop_­callback objects are synchronously called.
If an invocation of a callback exits via an exception then terminate is called ([except.terminate]).
[Note
:
A stop request includes notifying all condition variables of type condition_­variable_­any temporarily registered during an interruptible wait ([thread.condvarany.intwait]).
— end note
]
Postconditions: stop_­possible() is false or stop_­requested() is true.
Returns: true if this call made a stop request; otherwise false.