@@ -244,6 +244,8 @@ impl Condvar {
244
244
/// # Examples
245
245
///
246
246
/// ```
247
+ /// #![feature(wait_until)]
248
+ ///
247
249
/// use std::sync::{Arc, Mutex, Condvar};
248
250
/// use std::thread;
249
251
///
@@ -261,7 +263,7 @@ impl Condvar {
261
263
/// // Wait for the thread to start up.
262
264
/// let &(ref lock, ref cvar) = &*pair;
263
265
/// // As long as the value inside the `Mutex` is false, we wait.
264
- /// cvar.wait_until(lock.lock().unwrap(), |started| { started });
266
+ /// let _guard = cvar.wait_until(lock.lock().unwrap(), |started| { * started }).unwrap( );
265
267
/// ```
266
268
#[ unstable( feature = "wait_until" , issue = "47960" ) ]
267
269
pub fn wait_until < ' a , T , F > ( & self , mut guard : MutexGuard < ' a , T > ,
@@ -445,6 +447,8 @@ impl Condvar {
445
447
/// # Examples
446
448
///
447
449
/// ```
450
+ /// #![feature(wait_timeout_until)]
451
+ ///
448
452
/// use std::sync::{Arc, Mutex, Condvar};
449
453
/// use std::thread;
450
454
/// use std::time::Duration;
@@ -462,8 +466,8 @@ impl Condvar {
462
466
///
463
467
/// // wait for the thread to start up
464
468
/// let &(ref lock, ref cvar) = &*pair;
465
- /// let result = cvar.wait_timeout_until(lock, Duration::from_millis(100), |started| {
466
- /// started
469
+ /// let result = cvar.wait_timeout_until(lock.lock().unwrap() , Duration::from_millis(100), |started| {
470
+ /// * started
467
471
/// }).unwrap();
468
472
/// if result.1.timed_out() {
469
473
/// // timed-out without the condition ever evaluating to true.
@@ -613,6 +617,7 @@ impl Drop for Condvar {
613
617
614
618
#[ cfg( test) ]
615
619
mod tests {
620
+ /// #![feature(wait_until)]
616
621
use sync:: mpsc:: channel;
617
622
use sync:: { Condvar , Mutex , Arc } ;
618
623
use sync:: atomic:: { AtomicBool , Ordering } ;
@@ -699,9 +704,9 @@ mod tests {
699
704
// Wait for the thread to start up.
700
705
let & ( ref lock, ref cvar) = & * pair;
701
706
let guard = cvar. wait_until ( lock. lock ( ) . unwrap ( ) , |started| {
702
- started
707
+ * started
703
708
} ) ;
704
- assert ! ( * guard) ;
709
+ assert ! ( * guard. unwrap ( ) ) ;
705
710
}
706
711
707
712
#[ test]
@@ -730,7 +735,7 @@ mod tests {
730
735
let c = Arc :: new ( Condvar :: new ( ) ) ;
731
736
732
737
let g = m. lock ( ) . unwrap ( ) ;
733
- let ( _g, wait) = c. wait_timeout_until ( g, Duration :: from_millis ( 1 ) , || { false } ) . unwrap ( ) ;
738
+ let ( _g, wait) = c. wait_timeout_until ( g, Duration :: from_millis ( 1 ) , |_ | { false } ) . unwrap ( ) ;
734
739
// no spurious wakeups. ensure it timed-out
735
740
assert ! ( wait. timed_out( ) ) ;
736
741
}
@@ -742,7 +747,7 @@ mod tests {
742
747
let c = Arc :: new ( Condvar :: new ( ) ) ;
743
748
744
749
let g = m. lock ( ) . unwrap ( ) ;
745
- let ( _g, wait) = c. wait_timeout_until ( g, Duration :: from_millis ( 0 ) , || { true } ) . unwrap ( ) ;
750
+ let ( _g, wait) = c. wait_timeout_until ( g, Duration :: from_millis ( 0 ) , |_ | { true } ) . unwrap ( ) ;
746
751
// ensure it didn't time-out even if we were not given any time.
747
752
assert ! ( !wait. timed_out( ) ) ;
748
753
}
@@ -753,15 +758,16 @@ mod tests {
753
758
let pair = Arc :: new ( ( Mutex :: new ( false ) , Condvar :: new ( ) ) ) ;
754
759
let pair_copy = pair. clone ( ) ;
755
760
761
+ let & ( ref m, ref c) = & * pair;
756
762
let g = m. lock ( ) . unwrap ( ) ;
757
- let t = thread:: spawn ( move || {
758
- let & ( ref lock, ref cvar) = & * pair2 ;
763
+ let _t = thread:: spawn ( move || {
764
+ let & ( ref lock, ref cvar) = & * pair_copy ;
759
765
let mut started = lock. lock ( ) . unwrap ( ) ;
760
766
thread:: sleep ( Duration :: from_millis ( 1 ) ) ;
761
- started = true ;
767
+ * started = true ;
762
768
cvar. notify_one ( ) ;
763
769
} ) ;
764
- let ( g2, wait) = c. wait_timeout_until ( g, Duration :: from_millis ( u64:: MAX ) , |& notified| {
770
+ let ( g2, wait) = c. wait_timeout_until ( g, Duration :: from_millis ( u64:: MAX ) , |& mut notified| {
765
771
notified
766
772
} ) . unwrap ( ) ;
767
773
// ensure it didn't time-out even if we were not given any time.
0 commit comments