[][src]Struct may::sync::SyncFlag

pub struct SyncFlag { /* fields omitted */ }

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 SyncFalg 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();

Methods

impl SyncFlag[src]

pub fn new() -> Self[src]

create a SyncFlag with the initial value

pub fn wait(&self)[src]

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

pub fn wait_timeout(&self, dur: Duration) -> bool[src]

same as wait except that with an extra timeout value return false if timeout happened

pub fn fire(&self)[src]

set the SyncFlag to true and would wakeup all threads/coroutines that are calling wait

pub fn is_fired(&self) -> bool[src]

return the current SyncFlag value

Trait Implementations

impl Default for SyncFlag[src]

impl Debug for SyncFlag[src]

Auto Trait Implementations

impl Send for SyncFlag

impl Sync for SyncFlag

impl Unpin for SyncFlag

impl !UnwindSafe for SyncFlag

impl !RefUnwindSafe for SyncFlag

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]