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

Mention that it's not actually a data race #32538

Merged
merged 1 commit into from
Apr 6, 2016

Conversation

Manishearth
Copy link
Member

The example can't cause a data race since different indices are accesed.

(perhaps we should use an example where i iterates twice?)

r? @steveklabnik

@tobz
Copy link

tobz commented Mar 28, 2016

(Rust newbie here, just for context)

Is it the compiler actually looking and saying: "well, data is being access in another thread, so it's not safe" or simply that it's being accessed in a closure, another scope, somewhere where data could change out from under it?

I understand the wording being used is because of the nature of explaining concurrency -- which boils down to threads -- but it seems like it might be clearer to express it in the general terms that the Rust documentation seems to explain ownership.... so long as that's what the compiler sees. If the compiler actually can differentiate between where data is being accessed from, then I mostly take back this entire comment. :P

Just a thought.

@Manishearth
Copy link
Member Author

Is it the compiler actually looking and saying: "well, data is being access in another thread, so it's not safe" or simply that it's being accessed in a closure, another scope, somewhere where data could change out from under it?

Somewhat the latter, but not exactly. What the compiler sees (and what you should see too) is that data was moved out, so it doesn't even exist to be used again the second time around. It doesn't notice the concurrency issues, not just yet.

@tobz
Copy link

tobz commented Mar 28, 2016

The current wording feels like 75% about how a smart, outside observer can tell that the individual indices could be safely mutated without stepping on each other, and the other 25% is about what situation could actually cause a problem. The whole paragraph seems to ignore the explanation you posted above.

Does my summary make sense to you? Do you think it would be clearer to make a small mention, something along the lines of: "while this program may not appear to overwrite individual indices, the compiler cannot infer which pieces of the data are being operated on, only that the variable has been moved elsewhere and isn't eligible for use when we go to spawn the second thread" ?

@Manishearth
Copy link
Member Author

I'd prefer if the program was modified so that it does conflict indices :)

@tobz
Copy link

tobz commented Mar 28, 2016

Ha! Given the section is about concurrency, fair enough.

I guess I would just like to put in a suggestion/plea for any explanation of the "data moving" aspect. As a Rust newbie, the ownership system is consistently the hardest piece of Rust to understand/remember. If that's the actual/current reason why the compiler complains, then it seems fitting to tell that.

At any rate, it's awesome to see the documentation be so quickly updated, driven by random comments on HN no less. :)

@Manishearth
Copy link
Member Author

The assumption here is that you've read the chapter on ownership and are very clear on what moving is by the time you reach this chapter 😄

(The full compiler error on this actually links to an extended explanation on ownership that is pretty nice too)

@tobz
Copy link

tobz commented Mar 28, 2016

Got me again! A fair point, indeed. :)

@bors
Copy link
Contributor

bors commented Mar 28, 2016

☔ The latest upstream changes (presumably #32529) made this pull request unmergeable. Please resolve the merge conflicts.

@steveklabnik
Copy link
Member

@Manishearth: this is out of date, but r=me whenever you rebase it :)

Conflicts:
	src/doc/book/concurrency.md
@Manishearth
Copy link
Member Author

@bors r=steveklabnik

@bors
Copy link
Contributor

bors commented Apr 4, 2016

📌 Commit a447124 has been approved by steveklabnik

@Manishearth
Copy link
Member Author

@bors rollup

Manishearth added a commit to Manishearth/rust that referenced this pull request Apr 6, 2016
…abnik

Mention that it's not actually a data race

The example can't cause a data race since different indices are accesed.

(perhaps we should use an example where i iterates twice?)

r? @steveklabnik
steveklabnik added a commit to steveklabnik/rust that referenced this pull request Apr 6, 2016
…abnik

Mention that it's not actually a data race

The example can't cause a data race since different indices are accesed.

(perhaps we should use an example where i iterates twice?)

r? @steveklabnik
steveklabnik added a commit to steveklabnik/rust that referenced this pull request Apr 6, 2016
…abnik

Mention that it's not actually a data race

The example can't cause a data race since different indices are accesed.

(perhaps we should use an example where i iterates twice?)

r? @steveklabnik
steveklabnik added a commit to steveklabnik/rust that referenced this pull request Apr 6, 2016
…abnik

Mention that it's not actually a data race

The example can't cause a data race since different indices are accesed.

(perhaps we should use an example where i iterates twice?)

r? @steveklabnik
bors added a commit that referenced this pull request Apr 6, 2016
Rollup of 12 pull requests

- Successful merges: #31762, #32538, #32634, #32668, #32679, #32691, #32724, #32727, #32744, #32761, #32766, #32774
- Failed merges:
@bors bors merged commit a447124 into rust-lang:master Apr 6, 2016
@allonsy allonsy mentioned this pull request Apr 8, 2016
Manishearth added a commit to Manishearth/rust that referenced this pull request Apr 10, 2016
Adds data race in docs

Thanks for all your hard work!
This is in reference to rust-lang#32733
I know there has been a discussion about this on PR rust-lang#32538 so you are welcome to keep the code as is or merge my documentation in.
Let me know what you think and/or if you want me to modify anything!
steveklabnik added a commit to steveklabnik/rust that referenced this pull request Apr 11, 2016
Adds data race in docs

Thanks for all your hard work!
This is in reference to rust-lang#32733
I know there has been a discussion about this on PR rust-lang#32538 so you are welcome to keep the code as is or merge my documentation in.
Let me know what you think and/or if you want me to modify anything!
@Manishearth Manishearth deleted the no-data-race branch December 2, 2016 19:03
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.

4 participants