pub struct SyncFlag { /* private fields */ }
Expand description
SyncFlag primitive
SyncFlag allow threads and coroutines to synchronize their actions like barrier.
A SyncFlag is an boolean value When the SyncFlag is false, any thread or coroutine wait on it would block until it’s value becomes true When the SyncFlag is true, any thread or coroutine wait on it would return immediately.
After the SyncFlag becomes true, it will never becomes false again.
Examples
use std::sync::Arc;
use may::coroutine;
use may::sync::SyncFlag;
let flag = Arc::new(SyncFlag::new());
let flag2 = flag.clone();
// spawn a coroutine, and then wait for it to start
unsafe {
coroutine::spawn(move || {
flag2.fire();
flag2.wait();
});
}
// wait for the coroutine to start up
flag.wait();
Implementations
sourceimpl SyncFlag
impl SyncFlag
sourcepub fn wait(&self)
pub fn wait(&self)
wait for a SyncFlag
if the SyncFlag value is bigger than zero the function returns immediately
otherwise it would block the until a fire
is executed
sourcepub fn wait_timeout(&self, dur: Duration) -> bool
pub fn wait_timeout(&self, dur: Duration) -> bool
same as wait
except that with an extra timeout value
return false if timeout happened
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for SyncFlag
impl Send for SyncFlag
impl Sync for SyncFlag
impl Unpin for SyncFlag
impl !UnwindSafe for SyncFlag
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more