Difference between revisions of "cpp/thread/stop source"
(Created page with "{{cpp/title|stop_source}} {{cpp/thread/stop_source/navbar}} {{ddcl | header=stop_token | since=c++20 | 1= class stop_source; }} The {{tt|stop_source}} class provides the mean...") |
(Added notes) |
||
Line 5: | Line 5: | ||
}} | }} | ||
− | The {{tt|stop_source}} class provides the means to issue a stop request, for {{tt|std::jthread}} cancellation. A stop request made for one {{tt|stop_source}} object is visible to all {{tt|stop_source}}s and {{tt|stop_token}}s of the same associated stop-state. Once a stop is requested, it cannot be withdrawn. Additional stop requests have no effect. | + | The {{tt|stop_source}} class provides the means to issue a stop request, such as for {{tt|std::jthread}} cancellation. A stop request made for one {{tt|stop_source}} object is visible to all {{tt|stop_source}}s and {{tt|std::stop_token}}s of the same associated stop-state; any {{tt|std::stop_callback}}(s) registered for associated {{tt|std::stop_token}}(s) will be invoked, and any {{lc|std::condition_variable_any}} objects waiting on associated {{tt|std::stop_token}}(s) will be awoken. |
+ | |||
+ | Once a stop is requested, it cannot be withdrawn. Additional stop requests have no effect. | ||
===Member functions=== | ===Member functions=== | ||
Line 29: | Line 31: | ||
{{dsc end}} | {{dsc end}} | ||
+ | ===Notes=== | ||
+ | For the purposes of {{tt|std::jthread}} cancellation the {{tt|stop_source}} object should be retrieved from the {{tt|std::jthread}} object using {{c|1=get_stop_source()}}; or stop should be requested directly from the {{tt|std::jthread}} object using {{c|1=request_stop()}}. This will then use the same associated stop-state as that passed into the {{tt|std::jthread}}'s invoked function argument (i.e., the function being executed on its thread). | ||
+ | |||
+ | For other uses, however, a {{tt|stop_source}} can be constructed separately using the default constructor, which creates new stop-state. | ||
===Example=== | ===Example=== | ||
{{todo}} | {{todo}} |
Revision as of 11:48, 14 December 2019
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_source
s and std::stop_token
s 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) | |
destructs the stop_source object (public member function) | |
assigns the stop_source object (public member function) | |
Modifiers | |
makes a stop request for the associated stop-state, if any (public member function) | |
swaps two stop_source objects (public member function) | |
Observers | |
returns a stop_token for the associated stop-state (public member function) | |
checks whether the associated stop-state has been requested to stop (public member function) | |
checks whether associated stop-state can be requested to stop (public member function) |
Non-member functions
(C++20) |
compares two std::stop_source objects (function) |
(C++20) |
specializes the std::swap algorithm (function) |
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
This section is incomplete |