Skip to content

Commit e517ee0

Browse files
authored
Rollup merge of #110056 - chenyukang:yukang/fix-110045, r=workingjubilee
Fix the example in document for WaitTimeoutResult::timed_out Fixes #110045
2 parents 4c9ac1e + d67d989 commit e517ee0

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

library/std/src/sync/condvar.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ impl WaitTimeoutResult {
2121
///
2222
/// # Examples
2323
///
24-
/// This example spawns a thread which will update the boolean value and
25-
/// then wait 100 milliseconds before notifying the condvar.
24+
/// This example spawns a thread which will sleep 20 milliseconds before
25+
/// updating a boolean value and then notifying the condvar.
2626
///
27-
/// The main thread will wait with a timeout on the condvar and then leave
28-
/// once the boolean has been updated and notified.
27+
/// The main thread will wait with a 10 millisecond timeout on the condvar
28+
/// and will leave the loop upon timeout.
2929
///
3030
/// ```
3131
/// use std::sync::{Arc, Condvar, Mutex};
@@ -49,14 +49,12 @@ impl WaitTimeoutResult {
4949
///
5050
/// // Wait for the thread to start up.
5151
/// let (lock, cvar) = &*pair;
52-
/// let mut started = lock.lock().unwrap();
5352
/// loop {
5453
/// // Let's put a timeout on the condvar's wait.
55-
/// let result = cvar.wait_timeout(started, Duration::from_millis(10)).unwrap();
56-
/// // 10 milliseconds have passed, or maybe the value changed!
57-
/// started = result.0;
58-
/// if *started == true {
59-
/// // We received the notification and the value has been updated, we can leave.
54+
/// let result = cvar.wait_timeout(lock.lock().unwrap(), Duration::from_millis(10)).unwrap();
55+
/// // 10 milliseconds have passed.
56+
/// if result.1.timed_out() {
57+
/// // timed out now and we can leave.
6058
/// break
6159
/// }
6260
/// }

0 commit comments

Comments
 (0)