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

4.2 KiB

[stopsource]

32 Concurrency support library [thread]

32.3 Stop tokens [thread.stoptoken]

32.3.5 Class stop_source [stopsource]

32.3.5.1 General [stopsource.general]

namespace std {class stop_source {public:// [stopsource.cons], constructors, copy, and assignment stop_source(); explicit stop_source(nostopstate_t) noexcept {}// [stopsource.mem], member functionsvoid swap(stop_source&) noexcept;

stop_token get_token() const noexcept; bool stop_possible() const noexcept; bool stop_requested() const noexcept; bool request_stop() noexcept; bool operator==(const stop_source& rhs) noexcept = default; private: shared_ptr<unspecified> stop-state; // exposition only};}

1

#

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

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

2

#

stop_source modelsstoppable-source,copyable,equality_comparable, andswappable.

32.3.5.2 Constructors, copy, and assignment [stopsource.cons]

🔗

stop_source();

1

#

Effects: Initializes stop-state with a pointer to a new stop state.

2

#

Postconditions: stop_possible() is true and stop_requested() is false.

3

#

Throws: bad_alloc if memory cannot be allocated for the stop state.

32.3.5.3 Member functions [stopsource.mem]

🔗

void swap(stop_source& rhs) noexcept;

1

#

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

🔗

stop_token get_token() const noexcept;

2

#

Returns: stop_token() if stop_possible() is false; otherwise a new associated stop_token object; i.e., its stop-state member is equal to the stop-state member of *this.

🔗

bool stop_possible() const noexcept;

3

#

Returns: stop-state != nullptr.

🔗

bool stop_requested() const noexcept;

4

#

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

🔗

bool request_stop() noexcept;

5

#

Effects: Executes a stop request operation ([stoptoken.concepts]) on the associated stop state, if any.