pub struct SyncStopper { /* private fields */ }Expand description
A cancellation primitive with Release/Acquire memory ordering.
Unlike Stopper, whose checks are Relaxed loads,
SyncStopper guarantees that all writes before cancel() are visible
to any clone that subsequently observes should_stop() == true.
Converts to StopToken via From/Into with zero
overhead — the existing Arc is reused, not double-wrapped.
§Performance
On x86-64 an Acquire load is an ordinary load, so a check costs what a
Stopper’s does. On aarch64 it is ldar on targets
without RCpc (Linux, Windows, Android, iOS) and ldapr with it (macOS):
on a Neoverse-N1, a compute-bound loop checking every 64 bytes measured
3–10% slower than with a Relaxed check (code placement alone moved the
same loop by similar amounts), and under 1% at a check per KiB or in
memory-bound loops (benchmarks/stopper-ordering-2026-10-06.md). On
ARMv6-M and ARMv7-M each check also executes a dmb. In a
StopToken it is checked through the vtable.
Implementations§
Source§impl SyncStopper
impl SyncStopper
Sourcepub fn cancel(&self)
pub fn cancel(&self)
Cancel with a Release swap.
All memory writes before a cancel() are visible to any clone that
observes should_stop() == true after it, even when several threads
cancel.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Check if cancelled with Acquire ordering.
If this returns true, all memory writes that happened before
the corresponding cancel() call are guaranteed to be visible.
Trait Implementations§
Source§impl Clone for SyncStopper
impl Clone for SyncStopper
Source§impl Debug for SyncStopper
impl Debug for SyncStopper
Source§impl Default for SyncStopper
impl Default for SyncStopper
Source§impl From<SyncStopper> for StopToken
Reuses the SyncStopper’s Arc (no allocation); checks go through the vtable.
impl From<SyncStopper> for StopToken
Reuses the SyncStopper’s Arc (no allocation); checks go through the vtable.
Source§fn from(stopper: SyncStopper) -> Self
fn from(stopper: SyncStopper) -> Self
Source§impl Stop for SyncStopper
impl Stop for SyncStopper
Auto Trait Implementations§
impl Freeze for SyncStopper
impl RefUnwindSafe for SyncStopper
impl Send for SyncStopper
impl Sync for SyncStopper
impl Unpin for SyncStopper
impl UnsafeUnpin for SyncStopper
impl UnwindSafe for SyncStopper
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneStop for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> DebouncedTimeoutExt for Twhere
T: Stop,
impl<T> DebouncedTimeoutExt for Twhere
T: Stop,
Source§fn with_debounced_timeout(self, duration: Duration) -> DebouncedTimeout<Self>
fn with_debounced_timeout(self, duration: Duration) -> DebouncedTimeout<Self>
Source§fn with_debounced_deadline(self, deadline: Instant) -> DebouncedTimeout<Self>
fn with_debounced_deadline(self, deadline: Instant) -> DebouncedTimeout<Self>
Source§impl<T> StopExt for Twhere
T: Stop,
impl<T> StopExt for Twhere
T: Stop,
Source§fn or<S: Stop>(self, other: S) -> OrStop<Self, S>
fn or<S: Stop>(self, other: S) -> OrStop<Self, S>
Source§fn into_boxed(self) -> BoxedStopwhere
Self: 'static,
fn into_boxed(self) -> BoxedStopwhere
Self: 'static,
use into_token(), whose StopToken checks the same way and is Clone
BoxedStop. Deprecated: use
into_token(), whose StopToken checks the
same way and is Clone.