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

create a SyncFlag with the initial value

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

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

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

return the current SyncFlag value

Trait Implementations

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.