At the very end of
|
/// use std::sync::{Arc, Mutex, Condvar}; |
|
/// use std::thread; |
|
/// |
|
/// let pair = Arc::new((Mutex::new(false), Condvar::new())); |
|
/// let pair2 = pair.clone(); |
|
/// |
|
/// // Inside of our lock, spawn a new thread, and then wait for it to start. |
|
/// thread::spawn(move|| { |
|
/// let (lock, cvar) = &*pair2; |
|
/// let mut started = lock.lock().unwrap(); |
|
/// *started = true; |
|
/// // We notify the condvar that the value has changed. |
|
/// cvar.notify_one(); |
|
/// }); |
|
/// |
|
/// // Wait for the thread to start up. |
|
/// let (lock, cvar) = &*pair; |
|
/// let mut started = lock.lock().unwrap(); |
|
/// while !*started { |
|
/// started = cvar.wait(started).unwrap(); |
|
/// } |
|
/// ``` |
and in all similar examples elsewhere in the file, there should be a
std::mem::drop(started) call. Leaving a condition variable's mutex held after we're no longer watching it will block and possibly deadlock notifier threads.
At the very end of
rust/src/libstd/sync/condvar.rs
Lines 89 to 110 in 6b561b4
std::mem::drop(started)call. Leaving a condition variable's mutex held after we're no longer watching it will block and possibly deadlock notifier threads.