[thread.stoptoken.intro] (original) (raw)

32 Thread support library [thread]

32.3 Stop tokens [thread.stoptoken]

32.3.1 Introduction [thread.stoptoken.intro]

This clause describes components that can be used to asynchonously request that an operation stops execution in a timely manner, typically because the result is no longer required.

Such a request is called a stop request.

stop_­source, stop_­token, and stop_­callbackimplement semantics of shared ownership of a stop state.

Any stop_­source, stop_­token, or stop_­callbackthat shares ownership of the same stop state is an associated stop_­source, stop_­token, or stop_­callback, respectively.

The last remaining owner of the stop state automatically releases the resources associated with the stop state.

A stop_­token can be passed to an operation which can either

A stop request made via a stop_­source will be visible to all associated stop_­token and stop_­source objects.

Once a stop request has been made it cannot be withdrawn (a subsequent stop request has no effect).

Callbacks registered via a stop_­callback object are called when a stop request is first made by any associated stop_­source object.

Calls to the functions request_­stop, stop_­requested, and stop_­possibledo not introduce data races.

A call to request_­stop that returns truesynchronizes with a call to stop_­requestedon an associated stop_­token or stop_­source object that returns true.

Registration of a callback synchronizes with the invocation of that callback.