Skip to content

Commit 0cea2b7

Browse files
author
Tshepang Lekhonkhobe
committed
doc: nits and fixes for thread API
1 parent dcc6ce2 commit 0cea2b7

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

src/libstd/thread.rs

Lines changed: 16 additions & 18 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,7 +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.
93+
//! itself is available via the `thread` method of the join guard.
9694
//!
9795
//! (Note: eventually, the `scoped` constructor will allow the parent and child
9896
//! threads to data that lives on the parent thread's stack, but some language
@@ -108,7 +106,7 @@
108106
//! use std::thread;
109107
//!
110108
//! thread::Builder::new().name("child1".to_string()).spawn(move || {
111-
//! println!("Hello, world!")
109+
//! println!("Hello, world!");
112110
//! });
113111
//! ```
114112
//!
@@ -121,7 +119,7 @@
121119
//! initially not present:
122120
//!
123121
//! * 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
122+
//! the token is available for its thread handle, at which point it atomically
125123
//! consumes the token. It may also return *spuriously*, without consuming the
126124
//! token. `thread::park_timeout()` does the same, but allows specifying a
127125
//! maximum time to block the thread for.
@@ -143,7 +141,7 @@
143141
//! * It avoids the need to allocate mutexes and condvars when building new
144142
//! synchronization primitives; the threads already provide basic blocking/signaling.
145143
//!
146-
//! * It can be implemented highly efficiently on many platforms.
144+
//! * It can be implemented very efficiently on many platforms.
147145
148146
#![stable(feature = "rust1", since = "1.0.0")]
149147

0 commit comments

Comments
 (0)