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

doc-book: Improve clarity of Sync in Concurrency #28463

Merged
merged 1 commit into from
Sep 20, 2015
Merged

doc-book: Improve clarity of Sync in Concurrency #28463

merged 1 commit into from
Sep 20, 2015

Conversation

critiqjo
Copy link

Fixes #28458

Details about Arc may be too soon to be described together with Sync... Tell me what you think.

r? @steveklabnik

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @steveklabnik (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 the contribution instructions for more information.

@@ -215,29 +220,15 @@ fn main() {
}
```


If we'd tried to use `Mutex<T>` without wrapping it in an `Arc<T>` we would have
Copy link
Author

Choose a reason for hiding this comment

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

The above code snippet without Arc will most likely be thought of like this, which gives a "capture of moved value" error...

@critiqjo
Copy link
Author

I have incorporated the changes you suggested. Please have a look at them...

@steveklabnik
Copy link
Member

Will try to do tonight or tomorrow.

@critiqjo
Copy link
Author

Made a few more improvements...

A `u32` is `Send` because we can make a copy. So we create a thread, ask it to calculate
the answer, and then it `send()`s us the answer over the channel.
Here we create 10 threads, asking each to calculate the square of a number (`i`
at the time of `spawn()`), and then `send()` back the answer over the channel.
Copy link
Author

Choose a reason for hiding this comment

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

Do you think it is unnecessary to point out "i at the time of spawn()" (yet again)..?

Copy link
Member

Choose a reason for hiding this comment

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

i think it's fine.

@critiqjo
Copy link
Author

I was reading "Closures" and found some scope for improvement in Returning closures:

But why doesn’t our closure implement &'static Fn? Well, as we discussed before, closures borrow their environment. And in this case, our environment is based on a stack-allocated 5, the num variable binding. So the borrow has a lifetime of the stack frame.

But shouldn't the primary reading of the error message be "expected a static reference, found an object"? Further, we could point out that one cannot -- create something, turn it into a static object, and then return a static reference to it...

The "reference to stack allocated num" part can be explained after the next example block...

If you agree with me in this, shall I make these changes in this PR (as a second commit), or should I issue a new PR?

@steveklabnik
Copy link
Member

@critiqjo yeah, let's keep the two things separate. I'm not sure exactly what you mean, but I'd rather talk about it in a new issue and or PR

@steveklabnik
Copy link
Member

@bors: r+ rollup

@bors
Copy link
Contributor

bors commented Sep 19, 2015

📌 Commit a0f214e has been approved by steveklabnik

Manishearth added a commit to Manishearth/rust that referenced this pull request Sep 20, 2015
…labnik

Fixes rust-lang#28458

Details about `Arc` may be too soon to be described together with `Sync`... Tell me what you think.

r? @steveklabnik
bors added a commit that referenced this pull request Sep 20, 2015
@bors bors merged commit a0f214e into rust-lang:master Sep 20, 2015
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