[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.3 Stop 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.5 Class 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.2 Member 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)
