pub struct Cond { /* private fields */ }Expand description
A goroutine-aware condition variable.
Like std::sync::Condvar but parks goroutines instead of OS threads,
so other goroutines sharing the same M continue to be scheduled while
waiters sleep.
Must be used from within a [go_lib::run] context.
Implementations§
Source§impl Cond
impl Cond
Sourcepub fn wait<'a, T>(
&self,
mu: &'a Mutex<T>,
guard: MutexGuard<'a, T>,
) -> MutexGuard<'a, T>
pub fn wait<'a, T>( &self, mu: &'a Mutex<T>, guard: MutexGuard<'a, T>, ) -> MutexGuard<'a, T>
Release guard, park the current goroutine until notified, then
re-acquire the mutex and return the new guard.
Spurious wakeups are possible; always re-check the predicate in a loop:
let mut guard = mu.lock().unwrap();
while !*guard {
guard = cnd.wait(&mu, guard);
}§Panics
Panics if called from outside a goroutine context (i.e. before run()).
Sourcepub fn notify_one(&self)
pub fn notify_one(&self)
Wake one waiting goroutine. No-op if there are no waiters.
Sourcepub fn notify_all(&self)
pub fn notify_all(&self)
Wake all waiting goroutines.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Cond
impl RefUnwindSafe for Cond
impl Unpin for Cond
impl UnsafeUnpin for Cond
impl UnwindSafe for Cond
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more