Skip to content

Commit 524327a

Browse files
committed
Rollup merge of #22689 - tshepang:thread-doc-improvements, r=steveklabnik
2 parents 1cc8b6e + fa4cb49 commit 524327a

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

src/libstd/thread.rs

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,25 @@
2828
//! a thread will unwind the stack, running destructors and freeing
2929
//! owned resources. Thread panic is unrecoverable from within
3030
//! the panicking thread (i.e. there is no 'try/catch' in Rust), but
31-
//! panic may optionally be detected from a different thread. If
32-
//! the main thread panics the application will exit with a non-zero
31+
//! the panic may optionally be detected from a different thread. If
32+
//! the main thread panics, the application will exit with a non-zero
3333
//! exit code.
3434
//!
3535
//! When the main thread of a Rust program terminates, the entire program shuts
3636
//! down, even if other threads are still running. However, this module provides
3737
//! convenient facilities for automatically waiting for the termination of a
38-
//! child thread (i.e., join), described below.
38+
//! child thread (i.e., join).
3939
//!
4040
//! ## The `Thread` type
4141
//!
42-
//! Already-running threads are represented via the `Thread` type, which you can
42+
//! Threads are represented via the `Thread` type, which you can
4343
//! get in one of two ways:
4444
//!
45-
//! * By spawning a new thread, e.g. using the `thread::spawn` constructor;
45+
//! * By spawning a new thread, e.g. using the `thread::spawn` function.
4646
//! * By requesting the current thread, using the `thread::current` function.
4747
//!
4848
//! Threads can be named, and provide some built-in support for low-level
49-
//! synchronization described below.
49+
//! synchronization (described below).
5050
//!
5151
//! The `thread::current()` function is available even for threads not spawned
5252
//! by the APIs of this module.
@@ -59,29 +59,27 @@
5959
//! use std::thread;
6060
//!
6161
//! thread::spawn(move || {
62-
//! println!("Hello, World!");
63-
//! // some computation here
62+
//! // some work here
6463
//! });
6564
//! ```
6665
//!
6766
//! In this example, the spawned thread is "detached" from the current
68-
//! thread, meaning that it can outlive the thread that spawned
69-
//! it. (Note, however, that when the main thread terminates all
70-
//! detached threads are terminated as well.)
67+
//! thread. This means that it can outlive its parent (the thread that spawned
68+
//! it), unless this parent is the main thread.
7169
//!
7270
//! ## Scoped threads
7371
//!
7472
//! Often a parent thread uses a child thread to perform some particular task,
7573
//! and at some point must wait for the child to complete before continuing.
76-
//! For this scenario, use the `scoped` constructor:
74+
//! For this scenario, use the `thread::scoped` function:
7775
//!
7876
//! ```rust
7977
//! use std::thread;
8078
//!
8179
//! let guard = thread::scoped(move || {
82-
//! println!("Hello, World!");
83-
//! // some computation here
80+
//! // some work here
8481
//! });
82+
//!
8583
//! // do some other work in the meantime
8684
//! let output = guard.join();
8785
//! ```
@@ -92,11 +90,7 @@
9290
//! terminates) when it is dropped. You can join the child thread in
9391
//! advance by calling the `join` method on the guard, which will also
9492
//! return the result produced by the thread. A handle to the thread
95-
//! itself is available via the `thread` method on the join guard.
96-
//!
97-
//! (Note: eventually, the `scoped` constructor will allow the parent and child
98-
//! threads to data that lives on the parent thread's stack, but some language
99-
//! changes are needed before this is possible.)
93+
//! itself is available via the `thread` method of the join guard.
10094
//!
10195
//! ## Configuring threads
10296
//!
@@ -108,7 +102,7 @@
108102
//! use std::thread;
109103
//!
110104
//! thread::Builder::new().name("child1".to_string()).spawn(move || {
111-
//! println!("Hello, world!")
105+
//! println!("Hello, world!");
112106
//! });
113107
//! ```
114108
//!
@@ -121,7 +115,7 @@
121115
//! initially not present:
122116
//!
123117
//! * The `thread::park()` function blocks the current thread unless or until
124-
//! the token is available for its thread handle, at which point It atomically
118+
//! the token is available for its thread handle, at which point it atomically
125119
//! consumes the token. It may also return *spuriously*, without consuming the
126120
//! token. `thread::park_timeout()` does the same, but allows specifying a
127121
//! maximum time to block the thread for.
@@ -143,7 +137,7 @@
143137
//! * It avoids the need to allocate mutexes and condvars when building new
144138
//! synchronization primitives; the threads already provide basic blocking/signaling.
145139
//!
146-
//! * It can be implemented highly efficiently on many platforms.
140+
//! * It can be implemented very efficiently on many platforms.
147141
148142
#![stable(feature = "rust1", since = "1.0.0")]
149143

0 commit comments

Comments
 (0)