diff options
| author | bors <bors@rust-lang.org> | 2017-05-09 16:31:07 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-05-09 16:31:07 +0000 |
| commit | 644fc403dda0fb51facdc6b8c26a3165512f33ae (patch) | |
| tree | fce3da654adadc678dacfd316b3191c0b7597113 /src/libstd/thread | |
| parent | f3fc547194d22dc673274ac20e9a7b1e607cb862 (diff) | |
| parent | 323a774c2f64619623c45aec068cf6c1c905d314 (diff) | |
| download | rust-644fc403dda0fb51facdc6b8c26a3165512f33ae.tar.gz rust-644fc403dda0fb51facdc6b8c26a3165512f33ae.zip | |
Auto merge of #41814 - gamazeps:thread-struct-doc, r=steveklabnik
[Doc] improve `thread::Thread` and `thread::Builder` documentations Part of #29378 - Adds information about the stack_size when using `Builder`. This might be considered too low level, but I assume that if someone wants to create their own builder instead of using `thread::spawn` they may be interested in that info. - Updates the `thread::Thread` structure doc, mostly by explaining how to get one, the previous example was removed because it was not related to `thread::Thread`, but rather to `thread::Builder::name`. Not much is present there, mostly because this API is not often used (the only method that seems useful is `unpark`, which is documented in #41809).
Diffstat (limited to 'src/libstd/thread')
| -rw-r--r-- | src/libstd/thread/mod.rs | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index 04cd28df445..1bb0d9f3bab 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -244,6 +244,11 @@ impl Builder { /// Generates the base configuration for spawning a thread, from which /// configuration methods can be chained. /// + /// If the [`stack_size`] field is not specified, the stack size + /// will be the `RUST_MIN_STACK` environment variable, if it is + /// not specified either, a sensible default size will be set (2MB as + /// of the writting of this doc). + /// /// # Examples /// /// ``` @@ -259,6 +264,8 @@ impl Builder { /// /// handler.join().unwrap(); /// ``` + /// + /// [`stack_size`]: ../../std/thread/struct.Builder.html#method.stack_size #[stable(feature = "rust1", since = "1.0.0")] pub fn new() -> Builder { Builder { @@ -728,31 +735,21 @@ struct Inner { #[stable(feature = "rust1", since = "1.0.0")] /// A handle to a thread. /// -/// You can use it to identify a thread (by name, for example). Most of the -/// time, there is no need to directly create a `Thread` struct using the -/// constructor, instead you should use a function like `spawn` to create -/// new threads, see the docs of [`Builder`] and [`spawn`] for more. +/// Threads are represented via the `Thread` type, which you can get in one of +/// two ways: /// -/// # Examples +/// * By spawning a new thread, e.g. using the [`thread::spawn`][`spawn`] +/// function, and calling [`thread`][`JoinHandle::thread`] on the +/// [`JoinHandle`]. +/// * By requesting the current thread, using the [`thread::current`] function. +/// +/// The [`thread::current`] function is available even for threads not spawned +/// by the APIs of this module. +/// +/// There is usualy no need to create a `Thread` struct yourself, one +/// should instead use a function like `spawn` to create new threads, see the +/// docs of [`Builder`] and [`spawn`] for more details. /// -/// ```no_run -/// # // Note that this example isn't executed by default because it causes -/// # // deadlocks on Windows unfortunately (see #25824) -/// use std::thread::Builder; -/// -/// for i in 0..5 { -/// let thread_name = format!("thread_{}", i); -/// Builder::new() -/// .name(thread_name) // Now you can identify which thread panicked -/// // thanks to the handle's name -/// .spawn(move || { -/// if i == 3 { -/// panic!("I'm scared!!!"); -/// } -/// }) -/// .unwrap(); -/// } -/// ``` /// [`Builder`]: ../../std/thread/struct.Builder.html /// [`spawn`]: ../../std/thread/fn.spawn.html |
