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.

Synopsis

Declared in <bslstl_stoptoken.h>

class stop_source;

Member Functions

Name

Description

stop_source [constructor]

Constructors

~stop_source [destructor]

Destroy this object.

operator=

Assignment operators

get_token

Return a stop_token that refers to the stop state (or lack thereof) that *this refers to.

request_stop

If *this refers to a stop state and that stop state has not had a stop requested yet, atomically request a stop on that stop state, invoke all registered callbacks in an unspecified order, and finally return true. Otherwise, return false. If this function returns true, the call synchronizes with any call to stop_requested that returns true. A call to request_stop that is potentially concurrent with a call to stop_requested, stop_possible, or request_stop does not cause a data race.

stop_possible

Return true if *this refers to a stop state, and false otherwise. A call to stop_possible that is potentially concurrent with a call to stop_requested, stop_possible, or request_stop does not cause a data race.

stop_requested

Return true if *this refers to a stop state on which request_stop has been called, and false otherwise. If this function returns true, then the successful call to request_stop synchronizes with this call. A call to stop_requested that is potentially concurrent with a call to stop_requested, stop_possible, or request_stop does not cause a data race.

swap

Set *this to refer to the stop state (or lack thereof) that the specified other referred to, and vice versa. Equivalent to swap(*this, other).

Friends

Name

Description

bsl::swap

Set lhs to refer to the stop state (or lack thereof) that rhs referred to before the call, and vice versa. Implementation note: this function is required by the standard to be a hidden friend ([hidden.friends], [stopsource.general]).

bsl::operator==

Return true if the specified lhs and rhs refer to the same stop state, or if neither refers to a stop state; false otherwise. Implementation note: this function is required by the standard to be a hidden friend ([hidden.friends], [stopsource.general]).

Created with MrDocs