[#bsl-stop_token]
= xref:bsl.adoc[bsl]::stop&lowbar;token
:relfileprefix: ../
:mrdocs:

This class is a mechanism for observing cancellation requests&period; An object of this class either has (possibly shared) ownership of a stop state and can be used to observe whether a cancellation request has been made on that stop state, or does not own a stop state&period; A `stop&lowbar;token` cannot be used to make a cancellation request&period;

== Synopsis

Declared in `&lt;bslstl&lowbar;stoptoken&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
class stop&lowbar;token;
----

== Type Aliases

[cols="1,4"]
|===
| Name| Description
| xref:bsl/stop_token/callback_type.adoc[`callback&lowbar;type`] 
| Alias for `stop&lowbar;callback` parameterized by `t&lowbar;CALLBACK`&period;
|===


== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:bsl/stop_token/2constructor-06.adoc[`stop&lowbar;token`]         [.small]#[constructor]#
| Constructors
| xref:bsl/stop_token/2destructor.adoc[`&#126;stop&lowbar;token`] [.small]#[destructor]#
| Destroy this object&period;
| xref:bsl/stop_token/operator_assign-07.adoc[`operator&equals;`] 
| Assignment operators
| xref:bsl/stop_token/stop_possible.adoc[`stop&lowbar;possible`] 
| Return `true` if `&ast;this` refers to a stop state, and either a stop was already requested on that stop state or there is at least one `stop&lowbar;source` object that refers to that stop state (implying that a stop could still be requested using the `request&lowbar;stop` function), and `false` otherwise&period; A call to `stop&lowbar;possible` that is potentially concurrent with a call to `stop&lowbar;requested` or `stop&lowbar;possible` does not cause a data race&period;
| xref:bsl/stop_token/stop_requested.adoc[`stop&lowbar;requested`] 
| Return `true` if `&ast;this` refers to a stop state on which `request&lowbar;stop` has been called, and `false` otherwise&period; If this function returns `true`, then the successful call to `request&lowbar;stop` synchronizes with this call&period; A call to `stop&lowbar;requested` that is potentially concurrent with a call to `stop&lowbar;requested` or `stop&lowbar;possible` does not cause a data race&period;
| xref:bsl/stop_token/swap.adoc[`swap`] 
| Set `&ast;this` to refer to the stop state (or lack thereof) that the specified `other` referred to, and vice versa&period; Equivalent to `swap(&ast;this, other)`&period;
|===


== Friends

[cols="1,4"]
|===
| Name| Description
| `xref:bsl/swap-06da.adoc[bsl::swap]`
| Set `lhs` to refer to the stop state (or lack thereof) that `rhs` referred to, and vice versa&period; Implementation note&colon; this function is required by the standard to be a hidden friend (&lsqb;hidden&period;friends&rsqb;, &lsqb;stoptoken&period;general&rsqb;)&period;
| `xref:bsl/operator_eq-0c5.adoc[bsl::operator&equals;&equals;]`
| Return `true` if the specified `lhs` and `rhs` refer to the same stop state, or if neither refers to a stop state&semi; `false` otherwise&period; Implementation note&colon; this function is required by the standard to be a hidden friend (&lsqb;hidden&period;friends&rsqb;, &lsqb;stoptoken&period;general&rsqb;)&period;
| `xref:bsl/stop_callback-06.adoc[bsl::stop&lowbar;callback]`
| This class holds an object or reference of type `t&lowbar;CALLBACK` and, when constructed using a `stop&lowbar;token` that owns a stop state, schedules the held object or reference to be executed by the thread that requests cancellation on that stop state (if any)&period; However, if cancellation was already requested before the `stop&lowbar;callback` was constructed, the constructor invokes the callback immediately&period; If there is no stop state, or `request&lowbar;stop` is never called for the stop state, then the callback is not invoked&period; `stop&lowbar;callback` stores its callback within its own footprint, and thus never requires memory allocation&semi; however, `stop&lowbar;callback&lt;t&lowbar;CALLBACK&gt;` is an allocator&hyphen;aware class, if `t&lowbar;CALLBACK` is an allocator&hyphen;aware class, and any supplied allocator will then be passed to the constructor of `t&lowbar;CALLBACK`&period;
| `xref:bsl/stop_source.adoc[bsl::stop&lowbar;source]`
| This class is a mechanism for making and observing cancellation requests&period; 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&semi; it is also possible for a `stop&lowbar;source` object to not own a stop state&period; Due to its shared ownership semantics, it is safe to pass a copy of a `stop&lowbar;source` object to a callback that might outlive the original `stop&lowbar;source` object&semi; 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&lowbar;token`, which can be created by calling `stop&lowbar;source&colon;&colon;get&lowbar;token`&period;
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
