[Doc] Expands detach documentation in thread::JoinHande.#41981
[Doc] Expands detach documentation in thread::JoinHande.#41981bors merged 1 commit intorust-lang:masterfrom
detach documentation in thread::JoinHande.#41981Conversation
detach documentation in thread::JoinHande.detach documentation in thread::JoinHande.
src/libstd/thread/mod.rs
Outdated
There was a problem hiding this comment.
The example could be simplified with a plain scope or function instead of spawning two threads.
There’s no parent-child relationship between the threads in a process.
There was a problem hiding this comment.
The example could indeed be simplified to
fn main() {
{
thread::spawn(||{
thread::sleep(Duration::from_millis(10));
println!("hey");
});
}
thread::sleep(Duration::from_millis(1000));
}But this is not a form that I have ever encountered in real rust code, thus this example would not be very helpful.
On the other hand a thread spawning a new thread and being joined before the new thread is a behaviour that is encountered in real rust code. It is thus a bit more complex than needed, but I believe that it is also more helpful.
There are indeed no parent-child relationship between thread, this just seemed a good illustration, if you have a better name in mind I'll change for it.
There was a problem hiding this comment.
Well, the current example seems fine to me. But if improvements are possible, I'm open to it as long as it's easy to understand for readers.
There was a problem hiding this comment.
I am happy with either.
There was a problem hiding this comment.
Changed the child notation for spawned or associated.
On the other hand I still believe the current example to more helpful.
|
r? @rust-lang/docs |
src/libstd/thread/mod.rs
Outdated
There was a problem hiding this comment.
could you put an extra newline above here
src/libstd/thread/mod.rs
Outdated
There was a problem hiding this comment.
and below here, please? that is, an empty ///. This feels a bit cramped.
src/libstd/thread/mod.rs
Outdated
There was a problem hiding this comment.
I am happy with either.
72f33b3 to
c60ec47
Compare
|
Done :) |
|
@steveklabnik I think this is ready for another review and should be ready to go. |
src/libstd/thread/mod.rs
Outdated
There was a problem hiding this comment.
This should be marked no_run so we compile the code but don't run it during tests (we don't want this test to take a full second)
see also: https://doc.rust-lang.org/nightly/book/first-edition/documentation.html#running-documentation-tests
steveklabnik
left a comment
There was a problem hiding this comment.
r=me after the change @frewsxcv mentioned, thank you!
|
ping @gamazeps, just wanted to make sure this was still on your radar! |
|
@alexcrichton and you were right to do so :) |
Part of rust-lang#29378 . - Adds an example of a thread detaching. - Expands what `detaching` means.
|
Done :) |
|
@bors r+ rollup |
|
📌 Commit b76b9e1 has been approved by |
[Doc] Expands `detach` documentation in `thread::JoinHande`. Part of rust-lang#29378 . - Adds an example of a thread detaching. - Expands what `detaching` means. r? @steveklabnik
Part of #29378 .
detachingmeans.r? @steveklabnik