Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/thread/stop source"

From cppreference.com
< cpp‎ | thread
(add nostopstate_t)
(add nostopstate)
Line 23: Line 23:
 
{{dsc inc | cpp/thread/stop_source/dsc stop_requested}}
 
{{dsc inc | cpp/thread/stop_source/dsc stop_requested}}
 
{{dsc inc | cpp/thread/stop_source/dsc stop_possible}}
 
{{dsc inc | cpp/thread/stop_source/dsc stop_possible}}
 +
 +
{{dsc h1 | Constants}}
 +
{{dsc inc | cpp/thread/stop_source/dsc nostopstate}}
 
{{dsc end}}
 
{{dsc end}}
  

Revision as of 19:13, 14 December 2019

 
 
Concurrency support library
Threads
(C++11)
(C++20)
this_thread namespace
(C++11)
(C++11)
(C++11)
Cooperative cancellation
(C++20)
stop_source
(C++20)
Mutual exclusion
(C++11)
Generic lock management
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
Condition variables
(C++11)
Semaphores
Latches and Barriers
(C++20)
(C++20)
Futures
(C++11)
(C++11)
(C++11)
(C++11)
Safe Reclamation
(C++26)
Hazard Pointers
Atomic types
(C++11)
(C++20)
Initialization of atomic types
(C++11)(deprecated in C++20)
(C++11)(deprecated in C++20)
Memory ordering
Free functions for atomic operations
Free functions for atomic flags
 
 
Defined in header <stop_token>
class stop_source;
(since C++20)

The stop_source class provides the means to issue a stop request, such as for std::jthread cancellation. A stop request made for one stop_source object is visible to all stop_sources and std::stop_tokens of the same associated stop-state; any std::stop_callback(s) registered for associated std::stop_token(s) will be invoked, and any std::condition_variable_any objects waiting on associated std::stop_token(s) will be awoken.

Once a stop is requested, it cannot be withdrawn. Additional stop requests have no effect.

Contents

Member functions

constructs new stop_source object
(public member function) [edit]
destructs the stop_source object
(public member function) [edit]
assigns the stop_source object
(public member function) [edit]
Modifiers
makes a stop request for the associated stop-state, if any
(public member function) [edit]
swaps two stop_source objects
(public member function) [edit]
Observers
returns a stop_token for the associated stop-state
(public member function) [edit]
checks whether the associated stop-state has been requested to stop
(public member function) [edit]
checks whether associated stop-state can be requested to stop
(public member function) [edit]

Constants

a tag used for stop_source to indicate no associated stop-state upon construction
(tag)[edit]

Non-member functions

compares two std::stop_source objects
(function) [edit]
specializes the std::swap algorithm
(function) [edit]

Helper classes

placeholder type for use in stop_source constructor
(class) [edit]

Notes

For the purposes of std::jthread cancellation the stop_source object should be retrieved from the std::jthread object using get_stop_source(); or stop should be requested directly from the std::jthread object using request_stop(). This will then use the same associated stop-state as that passed into the std::jthread's invoked function argument (i.e., the function being executed on its thread).

For other uses, however, a stop_source can be constructed separately using the default constructor, which creates new stop-state.

Example