Skip to content

Commit

Permalink
doc: nits and fixes for thread API
Browse files Browse the repository at this point in the history
  • Loading branch information
tshepang committed Feb 22, 2015
1 parent dcc6ce2 commit 0cea2b7
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions src/libstd/thread.rs
Expand Up @@ -28,25 +28,25 @@
//! a thread will unwind the stack, running destructors and freeing
//! owned resources. Thread panic is unrecoverable from within
//! the panicking thread (i.e. there is no 'try/catch' in Rust), but
//! panic may optionally be detected from a different thread. If
//! the main thread panics the application will exit with a non-zero
//! the panic may optionally be detected from a different thread. If
//! the main thread panics, the application will exit with a non-zero
//! exit code.
//!
//! When the main thread of a Rust program terminates, the entire program shuts
//! down, even if other threads are still running. However, this module provides
//! convenient facilities for automatically waiting for the termination of a
//! child thread (i.e., join), described below.
//! child thread (i.e., join).
//!
//! ## The `Thread` type
//!
//! Already-running threads are represented via the `Thread` type, which you can
//! Threads are represented via the `Thread` type, which you can
//! get in one of two ways:
//!
//! * By spawning a new thread, e.g. using the `thread::spawn` constructor;
//! * By spawning a new thread, e.g. using the `thread::spawn` function.
//! * By requesting the current thread, using the `thread::current` function.
//!
//! Threads can be named, and provide some built-in support for low-level
//! synchronization described below.
//! synchronization (described below).
//!
//! The `thread::current()` function is available even for threads not spawned
//! by the APIs of this module.
Expand All @@ -59,29 +59,27 @@
//! use std::thread;
//!
//! thread::spawn(move || {
//! println!("Hello, World!");
//! // some computation here
//! // some work here
//! });
//! ```
//!
//! In this example, the spawned thread is "detached" from the current
//! thread, meaning that it can outlive the thread that spawned
//! it. (Note, however, that when the main thread terminates all
//! detached threads are terminated as well.)
//! thread. This means that it can outlive its parent (the thread that spawned
//! it), unless this parent is the main thread.
//!
//! ## Scoped threads
//!
//! Often a parent thread uses a child thread to perform some particular task,
//! and at some point must wait for the child to complete before continuing.
//! For this scenario, use the `scoped` constructor:
//! For this scenario, use the `thread::scoped` function:
//!
//! ```rust
//! use std::thread;
//!
//! let guard = thread::scoped(move || {
//! println!("Hello, World!");
//! // some computation here
//! // some work here
//! });
//!
//! // do some other work in the meantime
//! let output = guard.join();
//! ```
Expand All @@ -92,7 +90,7 @@
//! terminates) when it is dropped. You can join the child thread in
//! advance by calling the `join` method on the guard, which will also
//! return the result produced by the thread. A handle to the thread
//! itself is available via the `thread` method on the join guard.
//! itself is available via the `thread` method of the join guard.
//!
//! (Note: eventually, the `scoped` constructor will allow the parent and child
//! threads to data that lives on the parent thread's stack, but some language
Expand All @@ -108,7 +106,7 @@
//! use std::thread;
//!
//! thread::Builder::new().name("child1".to_string()).spawn(move || {
//! println!("Hello, world!")
//! println!("Hello, world!");
//! });
//! ```
//!
Expand All @@ -121,7 +119,7 @@
//! initially not present:
//!
//! * The `thread::park()` function blocks the current thread unless or until
//! the token is available for its thread handle, at which point It atomically
//! the token is available for its thread handle, at which point it atomically
//! consumes the token. It may also return *spuriously*, without consuming the
//! token. `thread::park_timeout()` does the same, but allows specifying a
//! maximum time to block the thread for.
Expand All @@ -143,7 +141,7 @@
//! * It avoids the need to allocate mutexes and condvars when building new
//! synchronization primitives; the threads already provide basic blocking/signaling.
//!
//! * It can be implemented highly efficiently on many platforms.
//! * It can be implemented very efficiently on many platforms.

#![stable(feature = "rust1", since = "1.0.0")]

Expand Down

0 comments on commit 0cea2b7

Please sign in to comment.