Skip to content

Commit bb06b13

Browse files
authored
Rollup merge of #79849 - Digital-Chaos:sleep-zero, r=m-ou-se
Clarify docs regarding sleep of zero duration Clarify that the behaviour of sleep() when given a duration of zero is actually platform specific.
2 parents ca98712 + bb2a27b commit bb06b13

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

library/std/src/thread/mod.rs

+9
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,15 @@ pub fn sleep_ms(ms: u32) {
775775
/// Platforms which do not support nanosecond precision for sleeping will
776776
/// have `dur` rounded up to the nearest granularity of time they can sleep for.
777777
///
778+
/// Currently, specifying a zero duration on Unix platforms returns immediately
779+
/// without invoking the underlying [`nanosleep`] syscall, whereas on Windows
780+
/// platforms the underlying [`Sleep`] syscall is always invoked.
781+
/// If the intention is to yield the current time-slice you may want to use
782+
/// [`yield_now`] instead.
783+
///
784+
/// [`nanosleep`]: https://linux.die.net/man/2/nanosleep
785+
/// [`Sleep`]: https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-sleep
786+
///
778787
/// # Examples
779788
///
780789
/// ```no_run

0 commit comments

Comments
 (0)