Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrote the thread struct docs #41543

Merged
merged 3 commits into from May 4, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions src/libstd/thread/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,21 +715,32 @@ 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.
///
/// # Examples
///
/// ```
/// use std::thread;
///
/// let handler = thread::Builder::new()
/// .name("foo".into())
/// .spawn(|| {
/// let thread = thread::current();
/// println!("thread name: {}", thread.name().unwrap());
/// })
/// .unwrap();
///
/// handler.join().unwrap();
/// 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

pub struct Thread {
inner: Arc<Inner>,
}
Expand Down