-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Closed
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Description
At the very end of
rust/src/libstd/sync/condvar.rs
Lines 89 to 110 in 6b561b4
| /// 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(); | |
| /// } | |
| /// ``` |
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.Metadata
Metadata
Assignees
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.