From 8ec47261e193b1f983b898a0d985b85e7fcb0668 Mon Sep 17 00:00:00 2001 From: Tomasz Miąsko Date: Tue, 26 Jul 2016 15:18:44 +0200 Subject: Use monotonic time with condition variables. Configure condition variables to use monotonic time using pthread_condattr_setclock on systems where this is possible. This fixes the issue when thread waiting on condition variable is woken up too late when system time is moved backwards. --- src/libstd/sync/condvar.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/libstd/sync') diff --git a/src/libstd/sync/condvar.rs b/src/libstd/sync/condvar.rs index 3c52ebc72f2..ca1a9905ebe 100644 --- a/src/libstd/sync/condvar.rs +++ b/src/libstd/sync/condvar.rs @@ -82,10 +82,14 @@ impl Condvar { /// notified. #[stable(feature = "rust1", since = "1.0.0")] pub fn new() -> Condvar { - Condvar { + let mut c = Condvar { inner: box sys::Condvar::new(), mutex: AtomicUsize::new(0), + }; + unsafe { + c.inner.init(); } + c } /// Blocks the current thread until this condition variable receives a -- cgit 1.4.1-3-g733a5