Skip to content

Commit e4ac447

Browse files
committed
Rollup merge of rust-lang#54646 - vn971:fix_std_thread_sleep, r=frewsxcv
improve documentation on std::thread::sleep
2 parents f7eb7fb + 7a0fa95 commit e4ac447

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/libstd/thread/mod.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -650,15 +650,17 @@ pub fn panicking() -> bool {
650650
panicking::panicking()
651651
}
652652

653-
/// Puts the current thread to sleep for the specified amount of time.
653+
/// Puts the current thread to sleep for at least the specified amount of time.
654654
///
655655
/// The thread may sleep longer than the duration specified due to scheduling
656-
/// specifics or platform-dependent functionality.
656+
/// specifics or platform-dependent functionality. It will never sleep less.
657657
///
658658
/// # Platform-specific behavior
659659
///
660-
/// On Unix platforms this function will not return early due to a
661-
/// signal being received or a spurious wakeup.
660+
/// On Unix platforms, the underlying syscall may be interrupted by a
661+
/// spurious wakeup or signal handler. To ensure the sleep occurs for at least
662+
/// the specified duration, this function may invoke that system call multiple
663+
/// times.
662664
///
663665
/// # Examples
664666
///
@@ -674,17 +676,19 @@ pub fn sleep_ms(ms: u32) {
674676
sleep(Duration::from_millis(ms as u64))
675677
}
676678

677-
/// Puts the current thread to sleep for the specified amount of time.
679+
/// Puts the current thread to sleep for at least the specified amount of time.
678680
///
679681
/// The thread may sleep longer than the duration specified due to scheduling
680-
/// specifics or platform-dependent functionality.
682+
/// specifics or platform-dependent functionality. It will never sleep less.
681683
///
682684
/// # Platform-specific behavior
683685
///
684-
/// On Unix platforms this function will not return early due to a
685-
/// signal being received or a spurious wakeup. Platforms which do not support
686-
/// nanosecond precision for sleeping will have `dur` rounded up to the nearest
687-
/// granularity of time they can sleep for.
686+
/// On Unix platforms, the underlying syscall may be interrupted by a
687+
/// spurious wakeup or signal handler. To ensure the sleep occurs for at least
688+
/// the specified duration, this function may invoke that system call multiple
689+
/// times.
690+
/// Platforms which do not support nanosecond precision for sleeping will
691+
/// have `dur` rounded up to the nearest granularity of time they can sleep for.
688692
///
689693
/// # Examples
690694
///

0 commit comments

Comments
 (0)