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

2.6 KiB

[stoptoken]

32 Concurrency support library [thread]

32.3 Stop tokens [thread.stoptoken]

32.3.4 Class stop_token [stoptoken]

32.3.4.1 General [stoptoken.general]

1

#

The class stop_token models the concept stoppable_token.

It shares ownership of its stop state, if any, with its associated stop_source object ([stopsource]) and any stop_token objects to which it compares equal.

namespace std {class stop_token {public:templateusing callback_type = stop_callback;

stop_token() noexcept = default; // [stoptoken.mem], 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

#

stop-state refers to the stop_token's associated stop state.

A stop_token object is disengaged when stop-state is empty.

32.3.4.2 Member functions [stoptoken.mem]

🔗

void swap(stop_token& rhs) noexcept;

1

#

Effects: Equivalent to:stop-state.swap(rhs.stop-state);

🔗

bool stop_requested() const noexcept;

2

#

Returns: true if stop-state refers to a stop state that has received a stop request; otherwise, false.

🔗

bool stop_possible() const noexcept;

3

#

Returns: false if

*this is disengaged, or

a stop request was not made and there are no associated stop_source objects;

otherwise, true.