- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
          [Doc] Expands detach documentation in thread::JoinHande.
          #41981
        
          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
Conversation
detach documentation in thread::JoinHande.detach documentation in thread::JoinHande.
              
          
                src/libstd/thread/mod.rs
              
                Outdated
          
        
      There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am happy with either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you put an extra newline above here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
        
          
                src/libstd/thread/mod.rs
              
                Outdated
          
        
      There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and below here, please? that is, an empty ///. This feels a bit cramped.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
        
          
                src/libstd/thread/mod.rs
              
                Outdated
          
        
      There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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