-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Fine-tune the Ordering for the atomic usages #2706
base: master
Are you sure you want to change the base?
Conversation
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 used SeqCst
in part because I didn't want to do the analysis necessary to demonstrate that a less restrictive ordering was correct, and also because I didn't perceive using SeqCst
to be a particular issue in most of these cases.
With that said, I buy all of the changes to Relaxed
here I think.
However, I'm unsure of the Require
/Release
changes in the ignore
crate. I think those warrant comments explaining their correctness.
} | ||
|
||
/// Returns true if this worker should quit immediately. | ||
fn is_quit_now(&self) -> bool { | ||
self.quit_now.load(AtomicOrdering::SeqCst) | ||
self.quit_now.load(AtomicOrdering::Acquire) |
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 think this and the Release
above need comments justifying why this is correct.
My reasoning is based on the following observations: Line 1501 calls ripgrep/crates/ignore/src/walk.rs Lines 1498 to 1504 in 648a65f
ripgrep/crates/ignore/src/walk.rs Lines 1654 to 1656 in 648a65f
Then, after executing is_quit_now at line 1669, send_quit is called at line 1680 to access the stack and perform another push .ripgrep/crates/ignore/src/walk.rs Lines 1669 to 1682 in 648a65f
Based on this sequence of operations, in the absence of a definitive |
I've reconsidered my earlier deduction and realized I overlooked a crucial detail. Before calling I would greatly appreciate your feedback on this observation. I'm eager for the potential merge and am ready to provide any further clarifications as needed. |
It might take me some time to look into this. I basically need to convince myself of your argument. If you want to get something merged more quickly, you could open a new PR with the less "interesting" changes and keep this PR focused on the changes to |
SeqCst
is overly restrictive. I believe that the ordering can be appropriately modified.In
messages
model, I believe thatMESSAGES
,IGNORE_MESSAGES
, andERRORED
are merely signals for multithreading purposes and do not synchronize with other locals. Therefore, usingRelaxed
ordering should suffice.In
lib
andutils
models,COUNTER
andNEXT_ID
are used for multithreading counting purposes, so usingRelaxed
ordering is sufficient.In
walk
model, theload
andstore
ofquit_now
should useAcquire
/Release
to ensure that thestack
is up-to-date.