pub struct AutoResetEvent(/* private fields */);Expand description
Wrapper of WaitEvent of type bool, which focuses on waiting for true with automatic reset to false.
Examples
use std::{ thread, sync::Arc, sync::atomic::{ AtomicU8, Ordering } };
use sync_wait_object::SignalWaitable;
let ev = AutoResetEvent::new();
let mut signal = ev.clone();
let mut next = AutoResetEvent::new();
let wait_next = next.clone();
let v = Arc::new(AtomicU8::new(0));
let v_setter = v.clone();
thread::spawn(move || {
v_setter.store(1, Ordering::SeqCst);
signal.set().unwrap();
wait_next.wait_until_set().unwrap();
v_setter.store(2, Ordering::SeqCst);
signal.set().unwrap();
});
ev.wait_until_set().unwrap();
assert_eq!(v.load(Ordering::SeqCst), 1);
next.set().unwrap();
ev.wait_until_set().unwrap();
assert_eq!(v.load(Ordering::SeqCst), 2);Implementations§
Trait Implementations§
Source§impl Clone for AutoResetEvent
impl Clone for AutoResetEvent
Source§fn clone(&self) -> AutoResetEvent
fn clone(&self) -> AutoResetEvent
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Deref for AutoResetEvent
impl Deref for AutoResetEvent
Auto Trait Implementations§
impl Freeze for AutoResetEvent
impl RefUnwindSafe for AutoResetEvent
impl Send for AutoResetEvent
impl Sync for AutoResetEvent
impl Unpin for AutoResetEvent
impl UnwindSafe for AutoResetEvent
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
Mutably borrows from an owned value. Read more