Rollup merge of #41543 - z1mvader:master, r=steveklabnik
Rewrote the thread struct docs https://github.com/rust-lang/rust/issues/29378
This commit is contained in:
commit
9f06dfb451
@ -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;
|
||||
/// use std::thread::Builder;
|
||||
///
|
||||
/// let handler = thread::Builder::new()
|
||||
/// .name("foo".into())
|
||||
/// .spawn(|| {
|
||||
/// let thread = thread::current();
|
||||
/// println!("thread name: {}", thread.name().unwrap());
|
||||
/// })
|
||||
/// .unwrap();
|
||||
///
|
||||
/// handler.join().unwrap();
|
||||
/// 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>,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user