pub struct Condvar { /* private fields */ }Expand description
A condition variable whose deadline waits follow a clock.
It mirrors std’s, except that it takes its clock when created, and its timed wait takes an absolute deadline. A wait releases the mutex while it blocks and relocks it before returning. Notifications are not buffered, and a wait may also return spuriously, so callers recheck their condition after every return.
Unlike std’s, a wait that starts while its thread unwinds from a panic, on a guard taken before the panic, poisons the mutex as it releases it.
Implementations§
Source§impl Condvar
impl Condvar
Sourcepub fn new(clock: &Clock) -> Self
pub fn new(clock: &Clock) -> Self
Creates a condition variable whose deadlines are read from clock.
Sourcepub fn wait<'a, T>(
&self,
guard: MutexGuard<'a, T>,
) -> LockResult<MutexGuard<'a, T>>
pub fn wait<'a, T>( &self, guard: MutexGuard<'a, T>, ) -> LockResult<MutexGuard<'a, T>>
Releases the mutex and blocks until notified, then relocks it.
If a thread panicked while holding the mutex, the relocked guard comes back inside an error.
Sourcepub fn wait_while<'a, T, F>(
&self,
guard: MutexGuard<'a, T>,
condition: F,
) -> LockResult<MutexGuard<'a, T>>
pub fn wait_while<'a, T, F>( &self, guard: MutexGuard<'a, T>, condition: F, ) -> LockResult<MutexGuard<'a, T>>
Blocks while condition holds, checking it with the mutex locked.
Returns with the mutex locked once condition is false. If a thread
panicked while holding the mutex, the relocked guard comes back inside
an error.
Sourcepub fn wait_deadline<'a, T>(
&self,
guard: MutexGuard<'a, T>,
deadline: Instant,
) -> LockResult<(MutexGuard<'a, T>, WaitTimeoutResult)>
pub fn wait_deadline<'a, T>( &self, guard: MutexGuard<'a, T>, deadline: Instant, ) -> LockResult<(MutexGuard<'a, T>, WaitTimeoutResult)>
Releases the mutex and blocks until notified or until the clock reaches
deadline, then relocks it.
A deadline already reached returns at once. As with std’s, the result reports a timeout only if the deadline ended the wait, however late the relock. A notification this wait takes wins over a reached deadline. If a thread panicked while holding the mutex, the guard and the result come back inside an error.
Sourcepub fn notify_one(&self)
pub fn notify_one(&self)
Wakes one thread waiting on this condvar, if any. The others keep waiting.
Sourcepub fn notify_all(&self)
pub fn notify_all(&self)
Wakes every thread waiting on this condvar.