pub struct SharedCondvar { /* private fields */ }
Expand description

Simple conditional variable that can be shared between processes and used with SharedMutex

Dropping conditional variable in creating process while it being used by another process will cause undefined behaviour. It is recommended to drop this conditional variable in creating process only after no other process has access to it.

For more information see pthread_cond_init, pthread_cond_wait, SharedMutex and SharedMemoryObject.

Example

let mut mutex = SharedMutex::new()?;
let mut condvar = SharedCondvar::new()?;

let pid = unsafe { fork() };
assert!(pid >= 0);

if pid == 0 {
    println!("child lock()");
    mutex.lock()?;
    println!("child wait()");
    condvar.wait(&mut mutex)?;
    println!("child notified");
    mutex.unlock()?;
    println!("child unlocked");
} else {
    sleep(Duration::from_millis(40));
    println!("parent notify()");
    condvar.notify_one()?;
}

Output:

child lock()
child wait()
parent notify()
child notified
child unlocked

Implementations§

Creates new SharedCondvar

Errors

If allocation or initialization fails returns error from last_os_error.

Waits on given mutex

This function will block until notified by another process

Errors

If any pthread call fails, returns error from last_os_error. For possible errors see pthread_cond_wait.

Notifies one of processes that are waiting on this condvar

Errors

If any pthread call fails, returns error from last_os_error. For possible errors see pthread_cond_signal.

Notifies all processes that are waiting on this condvar

Errors

If any pthread call fails, returns error from last_os_error. For possible errors see pthread_cond_broadcast.

Trait Implementations§

Executes the destructor for this 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 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.