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 2 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
21 changes: 13 additions & 8 deletions src/libstd/thread/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,22 +713,27 @@ struct Inner {

#[derive(Clone)]
#[stable(feature = "rust1", since = "1.0.0")]
/// A handle to a thread.
/// A handle to a thread, its just an abstract reference and as such
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"just" is a poor word for docs; this becomes better just dropping it.

Also, this summary is quite long; I think keeping the initial summary is fine, and putting this after:

/// A handle to a thread.
///
/// It is an abstract...

/// it can be used to identify a thread (by name, for example). In most
/// usage cases, this struct is not used directly.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not totally sure what you mean by "used directly" here, could you maybe elaborate a bit on what you're thinking?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well if you print debug most of the examples, those are JoinHandle's really, the threads are inside but you aren't really manipulating Thread structs

///
/// # Examples
///
/// ```
/// use std::thread;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't because of you, but while you're here.... this should be

use std::thread::{self, Builder};

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure i'll put that :)

///
/// let handler = thread::Builder::new()
/// .name("foo".into())
/// .spawn(|| {
/// let thread = thread::current();
/// println!("thread name: {}", thread.name().unwrap());
/// for i in 0..5 {
/// let thread_name = format!("thread_{}", i);
/// thread::Builder::new()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... and then this should be Builder::new()

/// .name(thread_name) // Now you can identify which thread panicked
/// // thanks to the handle's name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these lines wrapped to 80 cols? they look a bit short to me, but that could be wrong!

/// .spawn(move || {
/// if i == 3 {
/// panic!("I'm scared!!!");
/// }
/// })
/// .unwrap();
///
/// handler.join().unwrap();
/// }
/// ```
pub struct Thread {
inner: Arc<Inner>,
Expand Down