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/sys/common/condvar.rs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/libstd/sys/common') diff --git a/src/libstd/sys/common/condvar.rs b/src/libstd/sys/common/condvar.rs index 33734a88cf3..b6f29dd5fc3 100644 --- a/src/libstd/sys/common/condvar.rs +++ b/src/libstd/sys/common/condvar.rs @@ -27,6 +27,13 @@ impl Condvar { /// first used with any of the functions below. pub const fn new() -> Condvar { Condvar(imp::Condvar::new()) } + /// Prepares the condition variable for use. + /// + /// This should be called once the condition variable is at a stable memory + /// address. + #[inline] + pub unsafe fn init(&mut self) { self.0.init() } + /// Signals one waiter on this condition variable to wake up. #[inline] pub unsafe fn notify_one(&self) { self.0.notify_one() } -- cgit 1.4.1-3-g733a5