diff options
| author | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2016-07-26 15:18:44 +0200 |
|---|---|---|
| committer | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2016-07-31 12:47:52 +0200 |
| commit | 8ec47261e193b1f983b898a0d985b85e7fcb0668 (patch) | |
| tree | 5c4050b222e50ec613dd7a840dc3aa7db32ea5aa /src/libstd/sync | |
| parent | 724f811794bf30141922eb9ff26cd9ce7febe64e (diff) | |
| download | rust-8ec47261e193b1f983b898a0d985b85e7fcb0668.tar.gz rust-8ec47261e193b1f983b898a0d985b85e7fcb0668.zip | |
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.
Diffstat (limited to 'src/libstd/sync')
| -rw-r--r-- | src/libstd/sync/condvar.rs | 6 |
1 files changed, 5 insertions, 1 deletions
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 |
