From 8a85a85cea41e1e1faacb307f29b87abf935cdf3 Mon Sep 17 00:00:00 2001 From: James Wright Date: Wed, 23 Dec 2020 00:07:48 +0000 Subject: [PATCH 1/2] Clarify difference between unix/windows behaviour Updated to specify the underlying syscalls --- library/std/src/thread/mod.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs index 5d65f960fcd39..115919c966668 100644 --- a/library/std/src/thread/mod.rs +++ b/library/std/src/thread/mod.rs @@ -775,6 +775,14 @@ pub fn sleep_ms(ms: u32) { /// Platforms which do not support nanosecond precision for sleeping will /// have `dur` rounded up to the nearest granularity of time they can sleep for. /// +/// Currently, specifying a zero duration on Unix platforms returns immediately +/// without invoking the underlying [`nanosleep`] syscall, whereas on Windows +/// platforms the underlying [`Sleep`] syscall is always invoked. +/// If the intention is to yield the current time-slice you may want to use +/// [`yield_now`] instead. +/// [`nanosleep`]: https://linux.die.net/man/2/nanosleep +/// [`Sleep`]: https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-sleep +/// /// # Examples /// /// ```no_run From bb2a27ba4f5880d9842d4f2af2bf02a7253f303a Mon Sep 17 00:00:00 2001 From: James Wright Date: Fri, 15 Jan 2021 21:41:26 +0000 Subject: [PATCH 2/2] Update library/std/src/thread/mod.rs Fix link reference Co-authored-by: Joshua Nelson --- library/std/src/thread/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs index 115919c966668..a01e0b88b307a 100644 --- a/library/std/src/thread/mod.rs +++ b/library/std/src/thread/mod.rs @@ -780,6 +780,7 @@ pub fn sleep_ms(ms: u32) { /// platforms the underlying [`Sleep`] syscall is always invoked. /// If the intention is to yield the current time-slice you may want to use /// [`yield_now`] instead. +/// /// [`nanosleep`]: https://linux.die.net/man/2/nanosleep /// [`Sleep`]: https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-sleep ///