Skip to content

Commit b45e852

Browse files
author
Jonathan Turner
authored
Rollup merge of rust-lang#35239 - dns2utf8:doc_park_timeout, r=steveklabnik
Doc `std::thread::park_timeout` r? @steveklabnik
2 parents b026ac2 + 20721a4 commit b45e852

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/libstd/thread/mod.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,8 @@ pub fn park() {
447447
*guard = false;
448448
}
449449

450+
/// Use [park_timeout].
451+
///
450452
/// Blocks unless or until the current thread's token is made available or
451453
/// the specified duration has been reached (may wake spuriously).
452454
///
@@ -456,7 +458,10 @@ pub fn park() {
456458
/// preemption or platform differences that may not cause the maximum
457459
/// amount of time waited to be precisely `ms` long.
458460
///
459-
/// See the module doc for more detail.
461+
/// See the [module documentation][thread] for more detail.
462+
///
463+
/// [thread]: index.html
464+
/// [park_timeout]: fn.park_timeout.html
460465
#[stable(feature = "rust1", since = "1.0.0")]
461466
#[rustc_deprecated(since = "1.6.0", reason = "replaced by `std::thread::park_timeout`")]
462467
pub fn park_timeout_ms(ms: u32) {
@@ -478,6 +483,25 @@ pub fn park_timeout_ms(ms: u32) {
478483
///
479484
/// Platforms which do not support nanosecond precision for sleeping will have
480485
/// `dur` rounded up to the nearest granularity of time they can sleep for.
486+
///
487+
/// # Example
488+
///
489+
/// Waiting for the complete expiration of the timeout:
490+
///
491+
/// ```rust,no_run
492+
/// use std::thread::park_timeout;
493+
/// use std::time::{Instant, Duration};
494+
///
495+
/// let timeout = Duration::from_secs(2);
496+
/// let beginning_park = Instant::now();
497+
/// park_timeout(timeout);
498+
///
499+
/// while beginning_park.elapsed() < timeout {
500+
/// println!("restarting park_timeout after {:?}", beginning_park.elapsed());
501+
/// let timeout = timeout - beginning_park.elapsed();
502+
/// park_timeout(timeout);
503+
/// }
504+
/// ```
481505
#[stable(feature = "park_timeout", since = "1.4.0")]
482506
pub fn park_timeout(dur: Duration) {
483507
let thread = current();

0 commit comments

Comments
 (0)