Skip to content

Commit

Permalink
Rollup merge of #79849 - Digital-Chaos:sleep-zero, r=m-ou-se
Browse files Browse the repository at this point in the history
Clarify docs regarding sleep of zero duration

Clarify that the behaviour of sleep() when given a duration of zero is actually platform specific.
  • Loading branch information
JohnTitor authored Feb 10, 2021
2 parents ca98712 + bb2a27b commit bb06b13
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions library/std/src/thread/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,15 @@ 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
Expand Down

0 comments on commit bb06b13

Please sign in to comment.