Cooperative Stopping
StopSource and StopToken share one irreversible atomic stop request without requiring standard-library
stop-token support.
Copy a source to share signalling authority; copy its token to share read-only observation.
Both handles can be used across threads, and tokens remain valid after their sources are destroyed.
StopSource::requestStop() returns true only for the first request and never waits for observers.
isStopRequested() on either handle observes that request.
Destroying a source does not request stopping.
A default token never reports a stop request; a moved-from source cannot request stopping.
auto source = el::StopSource{};
const auto token = source.stopToken();
source.requestStop();
const auto stopping = token.isStopRequested(); // true
The signal is cooperative: it does not interrupt threads or system calls.
There is no reset, callback registration, or interruptible-wait API.
WorkerPool owns one source for all its operations and passes tokens to callables that accept them; see
Worker Pools.
Interface
-
class StopSource
A copyable shared source of irreversible, cooperative stop requests.
All copies signal the same state. Destruction does not request stopping.
Public Functions
-
StopSource()
Create a source with no stop request.
-
bool isStopRequested() const noexcept
Test whether any copy requested stopping.
-
bool requestStop() noexcept
Request stopping without waiting for observers.
- Returns:
True only for the call that first requests stopping; false for a moved-from source.
-
StopSource()