Skip to content

Update intro.md to fix thread spawning example #22298

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

Closed
wants to merge 1 commit into from

Conversation

diamondman
Copy link
Contributor

Fixed example threaded code in intro doc never printing results. Threads were created with Thread::spawn instead of Thread::scoped.

Fixed example threaded code in intro doc never printing results. Threads were created with Thread::spawn instead of Thread::scoped.
@rust-highfive
Copy link
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @huonw (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see CONTRIBUTING.md for more information.

@steveklabnik
Copy link
Member

Thank you!

@reem
Copy link
Contributor

reem commented Feb 13, 2015

I am not sure if this is the correct way to fix this, since this changes the code to be sequential (each Thread::scoped call returns a JoinGuard which will block at the end of each run of the for loop when it is dropped).

@steveklabnik
Copy link
Member

Ahh, this is true. This needs to change to use map and collect, like http://doc.rust-lang.org/intro.html#concurrency. Mind updating, @diamondman

@reem
Copy link
Contributor

reem commented Feb 13, 2015

@steveklabnik fwiw you don't need a guards variable in that code, might be easier to just add a hint to collect and remove the let, not sure what syntax you've introduced in terms of ::<T>() at that point, though.

@steveklabnik
Copy link
Member

IIRC, I wanted to make it a little more clear about when guards went out of scope, I think it's easier tos ee with an explicit variable, and yeah, it avoids ::<T> too.

@huonw
Copy link
Member

huonw commented Feb 13, 2015

r? @steveklabnik (transferring reviewership)

@rust-highfive rust-highfive assigned steveklabnik and unassigned huonw Feb 13, 2015
steveklabnik added a commit to steveklabnik/rust that referenced this pull request Feb 14, 2015
Fixed example threaded code in intro doc never printing results. Threads were created with Thread::spawn instead of Thread::scoped.
@steveklabnik
Copy link
Member

@diamondman are you interested in updating this PR? If so, please add "Closes #22419" to the new commit message.

If you're not, just let me know, and i'll fix it. thanks!

@diamondman
Copy link
Contributor Author

@steveklabnik I did not see updates for this until today somehow. I will close this and attempt to fix the example better using the correct locking structures.

Thanks everyone for suggestions.
Closes #22419

@diamondman diamondman closed this Feb 16, 2015
@diamondman diamondman changed the title Update intro.md to fix thread spawning example Update intro.md to fix thread spawning example Closes #22419 Feb 16, 2015
@diamondman diamondman changed the title Update intro.md to fix thread spawning example Closes #22419 Update intro.md to fix thread spawning example Feb 16, 2015
@diamondman
Copy link
Contributor Author

Sorry @steveklabnik but I am not sure how I am supposed to edit the commit message from github to correctly close the issue. I know how to make a commit from the command line that closes an issue but I have no changes to commit. Please advise so I do not make further pointless changes guessing.

@steveklabnik
Copy link
Member

No worries! A few things:

  1. you can update pull requests by force pushing to the branch. since your branch was named patch-1, i'm guessing that you did this from github's interface, yeah? I can show you how to update that, or opening another PR is fine too.
  2. git commit --amend will let you amend the commit message without modifying the commit.

@diamondman
Copy link
Contributor Author

Ok, I knew how to amend in the command line but I was worried that trying to push a change to the commit would require a force push and was not sure how this would work cross projects. I will try pushing that up. Thanks.

@diamondman
Copy link
Contributor Author

I pushed up the amended commit message to my fork and the issue you created shows a link to the updated commit.
Last two beginner questions for now:

  1. I do not see any links here about this pull request fixing that issue updated here, was I supposed to push it to rust-lang's rust repo, or is this how it is supposed to be?
  2. Am I required to do anything else for this operation to be complete?

@steveklabnik
Copy link
Member

Oh hey @diamondman , sorry I missed this. Two things:

  1. the amended commit message looks good! However, GitHub won't let me re-open this pull request for some reason, so you'll have to make a new one. https://github.com/diamondman/rust/compare/patch-1?expand=1 should do that.
  2. while you edited the commit message, the code is still the same. Can you change all the examples to use the style of the first one? IE:
use std::thread::Thread;

fn main() {
    let guards: Vec<_> = (0..10).map(|_| {
        Thread::scoped(|| {
            println!("Hello, world!");
        })
    }).collect();
}

With the map and collect, as well as the scoped. Do that, open another PR, and all should be good to go 😄

@diamondman
Copy link
Contributor Author

I have the patch ready. I am trying to test it but make check is yelling that it can not find valgrind (it is installed). I will make the new pull request as soon as I know it tests fine.

@steveklabnik
Copy link
Member

Hm, it shouldn't error on that, but if you want a quicker test, you can run rustdoc --test src/doc/intro.md and it will try to run the tests, that's what I do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants