-
Notifications
You must be signed in to change notification settings - Fork 13.8k
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
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 switched this from Arc to static as I find that easier to read.
/// // 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.
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.
Thank you, this should definitely be documented (this caveat was obvious to me, but I didn't think to point it out).
Could you also add a comment stating that this means that Waker
cannot be correctly implemented with thread::park
and unpark
alone? I know of at least one crate (pollster) that is subtly broken because it fails to account for this.
Where do you think such a comment should go? |
That seems worth a bug report, no?^^ |
/// get consumed by a *different* `park` in the same thread, leading to a deadlock. This also means | ||
/// you must not call unknown code between setting up for parking and calling `park`; for instance, | ||
/// if you invoke `println!`, that may itself call `park` and thus consume your `unpark` and cause a | ||
/// deadlock. |
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.
Where do you think such a comment should go?
Maybe here?
/// deadlock. | |
/// deadlock. | |
/// | |
/// In particular, this means that it is incorrect to... |
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.
Seems a bit odd to put this in the park
docs, this seems to be more of a Waker
thing, no?
I also realized I don't understand why this is insufficient for Waker
. I just know next to nothing about Waker
. I don't think just saying "it's insufficient" is very insightful as it raises the inevitable "why".
So I'm going to have to leave adding this comment to you or someone else.
Yeah, I'll file one (or maybe make a PR) once I get around to it. |
@rustbot ready |
I'll leave the comment about |
thread parking: fix docs and examples Fixes rust-lang#145816 r? `@joboet` Cc `@m-ou-se` `@Amanieu`
Rollup of 16 pull requests Successful merges: - #145660 (initial implementation of the darwin_objc unstable feature) - #145895 (thread parking: fix docs and examples) - #146308 (support integer literals in `${concat()}`) - #146323 (check before test for hardware capabilites in bits 32~63 of usize) - #146332 (tidy: make behavior of extra-checks more uniform) - #146338 (Extends AArch64 branch protection support to include GCS) - #146374 (Update `browser-ui-test` version to `0.22.2`) - #146413 (Improve suggestion in case a bare URL is surrounded by brackets) - #146426 (Bump miow to 0.60.1) - #146432 (Implement `Socket::take_error` for Hermit) - #146433 (rwlock tests: fix miri macos test regression) - #146435 (Change the default value of `gcc.download-ci-gcc` to `true`) - #146439 (fix cfg for poison test macro) - #146448 ([rustdoc] Correctly handle literal search on paths) - #146449 (Fix `libgccjit` symlink when we build GCC locally) - #146455 (test: remove an outdated normalization for rustc versions) Failed merges: - #146389 (Convert `no_std` and `no_core` to the new attribute infrastructure) r? `@ghost` `@rustbot` modify labels: rollup
thread parking: fix docs and examples Fixes rust-lang#145816 r? ``@joboet`` Cc ``@m-ou-se`` ``@Amanieu``
Rollup of 16 pull requests Successful merges: - #144549 (match clang's `va_arg` assembly on arm targets) - #145660 (initial implementation of the darwin_objc unstable feature) - #145895 (thread parking: fix docs and examples) - #146308 (support integer literals in `${concat()}`) - #146323 (check before test for hardware capabilites in bits 32~63 of usize) - #146332 (tidy: make behavior of extra-checks more uniform) - #146374 (Update `browser-ui-test` version to `0.22.2`) - #146413 (Improve suggestion in case a bare URL is surrounded by brackets) - #146426 (Bump miow to 0.60.1) - #146432 (Implement `Socket::take_error` for Hermit) - #146433 (rwlock tests: fix miri macos test regression) - #146435 (Change the default value of `gcc.download-ci-gcc` to `true`) - #146439 (fix cfg for poison test macro) - #146448 ([rustdoc] Correctly handle literal search on paths) - #146449 (Fix `libgccjit` symlink when we build GCC locally) - #146455 (test: remove an outdated normalization for rustc versions) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 15 pull requests Successful merges: - #144549 (match clang's `va_arg` assembly on arm targets) - #145895 (thread parking: fix docs and examples) - #146308 (support integer literals in `${concat()}`) - #146323 (check before test for hardware capabilites in bits 32~63 of usize) - #146332 (tidy: make behavior of extra-checks more uniform) - #146374 (Update `browser-ui-test` version to `0.22.2`) - #146413 (Improve suggestion in case a bare URL is surrounded by brackets) - #146426 (Bump miow to 0.60.1) - #146432 (Implement `Socket::take_error` for Hermit) - #146433 (rwlock tests: fix miri macos test regression) - #146435 (Change the default value of `gcc.download-ci-gcc` to `true`) - #146439 (fix cfg for poison test macro) - #146448 ([rustdoc] Correctly handle literal search on paths) - #146449 (Fix `libgccjit` symlink when we build GCC locally) - #146455 (test: remove an outdated normalization for rustc versions) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 15 pull requests Successful merges: - rust-lang/rust#144549 (match clang's `va_arg` assembly on arm targets) - rust-lang/rust#145895 (thread parking: fix docs and examples) - rust-lang/rust#146308 (support integer literals in `${concat()}`) - rust-lang/rust#146323 (check before test for hardware capabilites in bits 32~63 of usize) - rust-lang/rust#146332 (tidy: make behavior of extra-checks more uniform) - rust-lang/rust#146374 (Update `browser-ui-test` version to `0.22.2`) - rust-lang/rust#146413 (Improve suggestion in case a bare URL is surrounded by brackets) - rust-lang/rust#146426 (Bump miow to 0.60.1) - rust-lang/rust#146432 (Implement `Socket::take_error` for Hermit) - rust-lang/rust#146433 (rwlock tests: fix miri macos test regression) - rust-lang/rust#146435 (Change the default value of `gcc.download-ci-gcc` to `true`) - rust-lang/rust#146439 (fix cfg for poison test macro) - rust-lang/rust#146448 ([rustdoc] Correctly handle literal search on paths) - rust-lang/rust#146449 (Fix `libgccjit` symlink when we build GCC locally) - rust-lang/rust#146455 (test: remove an outdated normalization for rustc versions) r? `@ghost` `@rustbot` modify labels: rollup
Fixes #145816
r? @joboet
Cc @m-ou-se @Amanieu