Struct sync_wait_object::windows::AutoResetEvent
source · pub struct AutoResetEvent(_);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 copy 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 more