[−][src]Struct tarantool_module::fiber::Cond
Conditional variable for cooperative multitasking (fibers).
A cond (short for "condition variable") is a synchronization primitive
that allow fibers to yield until some predicate is satisfied. Fiber
conditions have two basic operations - wait()
and signal()
. cond.wait()
suspends execution of fiber (i.e. yields) until cond.signal() is called.
Example:
use tarantool_module::fiber::Cond; let cond = fiber.cond(); cond.wait();
The job will hang because cond.wait() – will go to sleep until the condition variable changes.
// Call from another fiber: cond.signal();
The waiting stopped, and the cond.wait() function returned true.
This example depended on the use of a global conditional variable with the arbitrary name cond. In real life, programmers would make sure to use different conditional variable names for different applications.
Unlike pthread_cond
, Cond doesn't require mutex/latch wrapping.
Implementations
impl Cond
[src]
- call Cond::new() to create a named condition variable, which will be called
cond
for examples in this section. - call cond.wait() to make a fiber wait for a signal via a condition variable.
- call cond.signal() to send a signal to wake up a single fiber that has executed cond.wait().
- call cond.broadcast() to send a signal to all fibers that have executed cond.wait().
pub fn new() -> Self
[src]
Instantiate a new fiber cond object.
pub fn signal(&self)
[src]
Wake one fiber waiting for the cond. Does nothing if no one is waiting. Does not yield.
pub fn broadcast(&self)
[src]
Wake up all fibers waiting for the cond. Does not yield.
pub fn wait_timeout(&self, timeout: f64) -> bool
[src]
Suspend the execution of the current fiber (i.e. yield) until signal() is called.
Like pthread_cond, FiberCond can issue spurious wake ups caused by explicit
Fiber::wakeup() or Fiber::cancel()
calls. It is highly recommended to wrap calls to this function into a loop
and check an actual predicate and fiber_testcancel()
on every iteration.
timeout
- timeout in seconds
Returns:
true
on signal() call or a spurious wake up.false
on timeout, diag is set toTimedOut
pub fn wait(&self) -> bool
[src]
Shortcut for wait_timeout().
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Cond
impl !Send for Cond
impl !Sync for Cond
impl Unpin for Cond
impl UnwindSafe for Cond
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,