-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Update docs of 'fence' #41217
Update docs of 'fence' #41217
Conversation
@Amanieu, would you mind reviewing this? Or at least, someone other than me should make sure it's accurate. This isn't my area of specialty. |
The example looks correct, and the explanation seems to be correct as well. |
Actually, I think the |
7a25dac
to
ed754cb
Compare
Thanks for comments! Removed |
src/libcore/sync/atomic.rs
Outdated
/// A fence 'A' which has [`Release`] ordering semantics, synchronizes with a | ||
/// fence 'B' with (at least) [`Acquire`] semantics, if and only if there exists | ||
/// atomic operations X and Y, both operating on some atomic object 'M' such | ||
/// that A is sequenced before X, Y is synchronized before B and Y observes | ||
/// the change to M. This provides a happens-before dependence between A and B. | ||
/// | ||
/// Thread 1 Thread 2 |
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.
Travis build is failing due to this line. I removed this line on my local environment and ./x.py test src/libcore completed successfully. Is this a bug, or intended?
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.
CommonMark considers indented text to be code:
http://spec.commonmark.org/0.27/#indented-code-blocks
As a result, it attempts to run this as a Rust program:
Thread 1 Thread 2
and that's not a valid Rust program :)
The best idea I have here is to wrap this diagram in three backticks and annotate with 'ignore' as seen here: (ignore the backslashes)
/// \```ignore
/// Thread 1 Thread 2
///
/// ...
/// ...
///
/// \```
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.
@frewsxcv Thank you!
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.
Unfortunately,
/// \```ignore
/// ...
/// \```
didn't work (the document got corrupted).
Instead, I tried ```text
and it worked fine.
ed754cb
to
f5b077a
Compare
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 have just a few minor nits...
The explanation and examples are correct.
Love the ASCII drawing and the example! It'd be good to see more of these. :)
src/libcore/sync/atomic.rs
Outdated
/// fences when the certain condition is met. Also, a fence prevents reordering | ||
/// of operations around a fence by CPU or a compiler. Each behavior is | ||
/// controlled by the value of [`Ordering`]. | ||
/// | ||
/// A fence 'A' which has [`Release`] ordering semantics, synchronizes with a |
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.
Perhaps this should say "A fence 'A' which has (at least) [Release
]..."? Note the text in parentheses.
src/libcore/sync/atomic.rs
Outdated
@@ -1550,12 +1550,30 @@ unsafe fn atomic_xor<T>(dst: *mut T, val: T, order: Ordering) -> T { | |||
|
|||
/// An atomic fence. | |||
/// | |||
/// A fence creates happens-before edges between other atomic operations or |
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.
s/edges/dependence/ or s/edges/relationships/
A fence creates happens-before relationships between not only atomic operations and fences, but also between normal memory operations.
src/libcore/sync/atomic.rs
Outdated
/// A fence creates happens-before edges between other atomic operations or | ||
/// fences when the certain condition is met. Also, a fence prevents reordering | ||
/// of operations around a fence by CPU or a compiler. Each behavior is | ||
/// controlled by the value of [`Ordering`]. |
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.
Nit: If you wish, you may rephrase this along the lines of: "Also, depending on the specified order
, a fence prevents certain types of memory operation reorderings around it by CPU or compiler."
@steveklabnik are you looking at this? |
I am not sure if @stjepang 's nits should be addressed before merging or not, basically. |
@stjepang Thank you for your feedbacks! |
Is it ok to reflect the nits? |
Yup!
…On Wed, Apr 19, 2017 at 11:19 AM, Seiichi Uchida ***@***.***> wrote:
Is it ok to reflect the nits?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#41217 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AABsigtufEOUWQIcKbjf7tHM0XSl1BMiks5rxiYRgaJpZM4M6HmX>
.
|
f5b077a
to
3fd8c8e
Compare
Sorry for being lazy... I pushed the changes suggested by @stjepang. Thanks again! |
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.
Looking good - just a few more grammar fixes, and then this is ready to go! :)
Thanks so much for taking an effort to improve the docs!
src/libcore/sync/atomic.rs
Outdated
/// A fence creates happens-before relationships between other atomic operations or | ||
/// fences when the certain condition is met. Also, depending of the specified | ||
/// `order`, a fence prevents reordering certain types of memory operations | ||
/// around a fence by CPU or a compiler. |
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.
s/a fence/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.
@stejpang Thank you for your advices! One question, are you referring to the last a fence
, or the second and the last ones?
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 just meant "around a fence" -> "around it". :)
But now that I think more about this, how about the following (slightly simplified) paragraph?
"Depending on the specified order
, a fence prevents the compiler and CPU from reordering certain types of memory operations around it. That creates synchronizes-with relationships between it and atomic operations or fences in other threads."
I think here it's more correct to talk about synchronizes-with rather than happens-before. Pretty much every two operations within a single thread already have a happens-before relationship.
Fences really just establish synchronizes-with relationships with fences/atomics in other threads.
See the following links for a clearer explanation:
http://preshing.com/20130702/the-happens-before-relation/
http://preshing.com/20130823/the-synchronizes-with-relation/
Sorry for being so pedantic :)
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 agree with you, since rust does not have a signal and fence
prohibits Relaxed
ordering.
Thank you very much for your explanation!
src/libcore/sync/atomic.rs
Outdated
/// fence 'B' with (at least) [`Acquire`] semantics, if and only if there exists | ||
/// atomic operations X and Y, both operating on some atomic object 'M' such | ||
/// A fence creates happens-before relationships between other atomic operations or | ||
/// fences when the certain condition is met. Also, depending of the specified |
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.
s/of/on/
src/libcore/sync/atomic.rs
Outdated
/// | ||
/// A fence 'A' which has (at least) [`Release`] ordering semantics, synchronizes | ||
/// with a fence 'B' with (at least) [`Acquire`] semantics, if and only if there | ||
/// exists operations X and Y, both operating on some atomic object 'M' such |
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.
s/exists/exist/
3fd8c8e
to
91a9866
Compare
@steveklabnik I think the nits were addressed. Can you look at this? |
@bors: r+ rollup thank you so much, and sorry about all of the delays. |
📌 Commit 91a9866 has been approved by |
…eveklabnik Update docs of 'fence' This PR updates the docs for `std::sync::atomic::fence` with an example and a diagram. Part of rust-lang#29377. r? @steveklabnik
This PR updates the docs for
std::sync::atomic::fence
with an example and a diagram.Part of #29377.
r? @steveklabnik