+ /// Block unless or until the current thread's token is made available or
+ /// the specified duration has been reached (may wake spuriously).
+ ///
+ /// The semantics of this function are equivalent to `park()` except that the
+ /// thread will be blocked for roughly no longer than dur. This method
+ /// should not be used for precise timing due to anomalies such as
+ /// preemption or platform differences that may not cause the maximum
+ /// amount of time waited to be precisely dur
+ ///
+ /// See the module doc for more detail.
+ #[unstable(feature = "std_misc", reason = "recently introduced")]
+ pub fn park_timeout(dur: Duration) {
+ let thread = Thread::current();
+ let mut guard = thread.inner.lock.lock().unwrap();
+ if !*guard {
+ let (g, _) = thread.inner.cvar.wait_timeout(guard, dur).unwrap();
+ guard = g;
+ }
+ *guard = false;
+ }
+