about summary refs log tree commit diff
path: root/src/libstd/thread.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstd/thread.rs')
-rw-r--r--src/libstd/thread.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/libstd/thread.rs b/src/libstd/thread.rs
index adc3b77407a..0216f324fdb 100644
--- a/src/libstd/thread.rs
+++ b/src/libstd/thread.rs
@@ -379,6 +379,19 @@ pub fn panicking() -> bool {
     unwind::panicking()
 }
 
+/// Put the current thread to sleep for the specified amount of time.
+///
+/// The thread may sleep longer than the duration specified due to scheduling
+/// specifics or platform-dependent functionality. Note that on unix platforms
+/// this function will not return early due to a signal being received or a
+/// spurious wakeup.
+#[unstable(feature = "thread_sleep",
+           reason = "recently added, needs an RFC, and `Duration` itself is \
+                     unstable")]
+pub fn sleep(dur: Duration) {
+    imp::sleep(dur)
+}
+
 /// Block unless or until the current thread's token is made available (may wake spuriously).
 ///
 /// See the module doc for more detail.
@@ -935,6 +948,12 @@ mod test {
         }
     }
 
+    #[test]
+    fn sleep_smoke() {
+        thread::sleep(Duration::milliseconds(2));
+        thread::sleep(Duration::milliseconds(-2));
+    }
+
     // NOTE: the corresponding test for stderr is in run-pass/task-stderr, due
     // to the test harness apparently interfering with stderr configuration.
 }