[#bsl-stop_source] = xref:bsl.adoc[bsl]::stop_source :relfileprefix: ../ :mrdocs: Mechanism for requesting and observing cancellation on a stop state. == Synopsis Declared in `<bslstl_stoptoken.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- class stop_source; ---- == Description This class is a mechanism for making and observing cancellation requests. An object of this class may have (possibly shared) ownership of a stop state, in which case it can be used to make a cancellation request or observe whether a cancellation request has been made on the owned stop state; it is also possible for a `stop_source` object to not own a stop state. Due to its shared ownership semantics, it is safe to pass a copy of a `stop_source` object to a callback that might outlive the original `stop_source` object; however, a callback that should only be able to observe a cancellation request, without being able to request cancellation itself, should instead be passed a `stop_token`, which can be created by calling `stop_source::get_token`. == Member Functions [cols="1,4"] |=== | Name| Description | xref:bsl/stop_source/2constructor-053.adoc[`stop_source`] [.small]#[constructor]# | Constructors | xref:bsl/stop_source/2destructor.adoc[`~stop_source`] [.small]#[destructor]# | Destroy this object. | xref:bsl/stop_source/operator_assign-00.adoc[`operator=`] | Assignment operators | xref:bsl/stop_source/get_token.adoc[`get_token`] | Return a `stop_token` that refers to the stop state (or lack thereof) that `*this` refers to. | xref:bsl/stop_source/request_stop.adoc[`request_stop`] | Request a stop on the referred stop state, if any and not yet stopped. | xref:bsl/stop_source/stop_possible.adoc[`stop_possible`] | Return whether this source currently refers to a stop state. | xref:bsl/stop_source/stop_requested.adoc[`stop_requested`] | Return whether a stop has been requested on the referred stop state. | xref:bsl/stop_source/swap.adoc[`swap`] | Exchange the stop states referred to by `*this` and `other`. |=== == Friends [cols="1,4"] |=== | Name| Description | `xref:bsl/swap-03fc.adoc[bsl::swap]` | Exchange the stop states referred to by `lhs` and `rhs`. | `xref:bsl/operator_eq-067.adoc[bsl::operator==]` | Return whether `lhs` and `rhs` refer to the same stop state. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#