Files
cppdraft_translate/cppdraft/stoptoken.md
2025-10-25 03:02:53 +03:00

80 lines
2.6 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[stoptoken]
# 32 Concurrency support library [[thread]](./#thread)
## 32.3 Stop tokens [[thread.stoptoken]](thread.stoptoken#stoptoken)
### 32.3.4 Class stop_token [stoptoken]
#### [32.3.4.1](#general) General [[stoptoken.general]](stoptoken.general)
[1](#general-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L826)
The class stop_token models the concept [stoppable_token](stoptoken.concepts#concept:stoppable_token "32.3.3Stop token concepts[stoptoken.concepts]")[.](#general-1.sentence-1)
It shares ownership of its stop state, if any,
with its associated stop_source object ([[stopsource]](stopsource "32.3.5Class stop_­source")) and
any stop_token objects to which it compares equal[.](#general-1.sentence-2)
namespace std {class stop_token {public:template<class CallbackFn>using callback_type = stop_callback<CallbackFn>;
stop_token() noexcept = default; // [[stoptoken.mem]](#mem "32.3.4.2Member functions"), member functionsvoid swap(stop_token&) noexcept; bool stop_requested() const noexcept; bool stop_possible() const noexcept; bool operator==(const stop_token& rhs) noexcept = default; private: shared_ptr<*unspecified*> *stop-state*; // *exposition only*};}
[2](#general-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L856)
*stop-state* refers to the stop_token's associated stop state[.](#general-2.sentence-1)
A stop_token object is disengaged when *stop-state* is empty[.](#general-2.sentence-2)
#### [32.3.4.2](#mem) Member functions [[stoptoken.mem]](stoptoken.mem)
[🔗](#lib:swap,stop_token)
`void swap(stop_token& rhs) noexcept;
`
[1](#mem-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L868)
*Effects*: Equivalent to:*stop-state*.swap(rhs.*stop-state*);
[🔗](#lib:stop_requested,stop_token)
`bool stop_requested() const noexcept;
`
[2](#mem-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L882)
*Returns*: true if *stop-state* refers to a stop state
that has received a stop request;
otherwise, false[.](#mem-2.sentence-1)
[🔗](#lib:stop_possible,stop_token)
`bool stop_possible() const noexcept;
`
[3](#mem-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L895)
*Returns*: false if
- [(3.1)](#mem-3.1)
*this is disengaged, or
- [(3.2)](#mem-3.2)
a stop request was not made
and there are no associated stop_source objects;
otherwise, true[.](#mem-3.sentence-1)