-
Notifications
You must be signed in to change notification settings - Fork 13.7k
thread parking: fix docs and examples #145895
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
base: master
Are you sure you want to change the base?
Conversation
The Miri subtree was changed cc @rust-lang/miri |
/// use std::time::Duration; | ||
/// | ||
/// let flag = Arc::new(AtomicBool::new(false)); | ||
/// let flag2 = Arc::clone(&flag); |
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 switches this from Arc to static as I find that easier to read.
/// while !flag2.load(Ordering::Relaxed) { | ||
/// println!("Parking thread"); | ||
/// while !FLAG.load(Ordering::Acquire) { | ||
/// // `eprintln!` does not do any thread parking internally so we can safely call it here. |
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 don't think we actually guarantee that eprintln!
does not park, so this comment is dubious.
/// // We want to wait until the flag is set. We *could* just spin, but using | ||
/// // park/unpark is more efficient. | ||
/// while !flag2.load(Ordering::Relaxed) { | ||
/// println!("Parking thread"); | ||
/// while !FLAG.load(Ordering::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 used release/acquire orderings for my variables since generally IMO one should only used relaxed when it is quite obviously the right thing, and I don't think that's obvious here at all. I then also changed the flag for consistency. If this flag indicates that some work was done (as flags often do), then it really should use release/acquire.
Fixes #145816
r? @joboet
Cc @m-ou-se @Amanieu