-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Rename std::thread::available_conccurrency
to std::thread::available_parallelism
#89324
Conversation
I don't have any objections to such a rename. Worth thinking about the cost of promoting the terminology distinction, given the divergence from the C++ name. I think people will understand what this does under either name. So the question is what will convey the concept most clearly taking into account both existing names and established terminology. |
In the case of hyper-threading, the word "concurrency" seems more accurate - the CPU is not offering X amount of parallelism, but it is recommending X amount of concurrency. |
Thinking about it further, I think this change seems reasonable. In practice, I think "parallel" is actually the more likely name. Would you consider also adding doc aliases for both |
@rfcbot merge |
Team member @joshtriplett has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
Ah yeah, good call. Pushed! |
The new name SGTM. The docs still contain a few mentions of the word "hardware." At the very least, we might want to update the opening line to be more consistent with the name of the routine. I do think it would be nice to perhaps mention the word hardware or "CPU" in the docs somewhere. Something like, "this often corresponds to the number of logical CPUs available to the current program, but not always. For example, in scenarios Foo and Bar, ..." Basically, to give a bit more detail on what folks can realistically expect in terms of some common environments. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
I like that suggestion quite a bit! - If it's okay with y'all, once we merge this I'll submit a follow-up to this PR with docs changes. |
@bors r+ |
📌 Commit 03fbc16 has been approved by |
🌲 The tree is currently closed for pull requests below priority 100. This pull request will be tested once the tree is reopened. |
…arth Rollup of 12 pull requests Successful merges: - rust-lang#87601 (Add functions to add unsigned and signed integers) - rust-lang#88523 (Expand documentation for `FpCategory`.) - rust-lang#89050 (refactor: VecDeques Drain fields to private) - rust-lang#89245 (refactor: make VecDeque's IterMut fields module-private, not just crate-private) - rust-lang#89324 (Rename `std::thread::available_conccurrency` to `std::thread::available_parallelism`) - rust-lang#89329 (print-type-sizes: skip field printing for primitives) - rust-lang#89501 (Note specific regions involved in 'borrowed data escapes' error) - rust-lang#89506 (librustdoc: Use correct heading levels.) - rust-lang#89528 (Fix suggestion to borrow when casting from pointer to reference) - rust-lang#89531 (library std, libc dependency update) - rust-lang#89588 (Add a test for generic_const_exprs) - rust-lang#89591 (fix: alloc-optimisation is only for rust llvm) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
A little side note for the overall process: it would really be nice if these kinds of changes, such as renaming, could be announced in the tracking issue. I know this pr links to the tracking issue, but GitHub doesn't send email for that. So for people like myself who mostly follow tracking issue using email I was in for a bit of a surprise that |
👍. I've gone ahead and nominated this suggestion for discussion during the next libs team meeting this Wednesday. |
…ocs, r=joshtriplett Improve `std::thread::available_parallelism` docs _Tracking issue: https://github.com/rust-lang/rust/issues/74479_ This PR reworks the documentation of `std::thread::available_parallelism`, as requested [here](rust-lang#89324 (comment)). ## Changes The following changes are made: - We've removed prior mentions of "hardware threads" and instead centers the docs around "parallelism" as a resource available to a program. - We now provide examples of when `available_parallelism` may return numbers that differ from the number of CPU cores in the host machine. - We now mention that the amount of available parallelism may change over time. - We make note of which platform components we don't take into account which more advanced users may want to take note of. - The example has been updated, which should be a bit easier to use. - We've added a docs alias to `num-cpus` which provides similar functionality to `available_parallelism`, and is one of the most popular crates on crates.io. --- Thanks! r? `@BurntSushi`
…Simulacrum kmc-solid: Fix SOLID target This PR is a follow-up for rust-lang#86191 and necessary to make the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets actually usable. - Bumps `libc` to 0.2.105, which includes <rust-lang/libc#2227>. - Applies the change made by rust-lang#89324 to this target's target-specific code.
…mulacrum kmc-solid: Fix SOLID target This PR is a follow-up for rust-lang#86191 and necessary to make the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets actually usable. - Bumps `libc` to 0.2.106, which includes <rust-lang/libc#2227>. - Applies the change made by rust-lang#89324 to this target's target-specific code.
Tracking issue: #74479
This PR renames
std::thread::available_conccurrency
tostd::thread::available_parallelism
.Rationale
The API was initially named
std::thread::hardware_concurrency
, mirroring the C++ API of the same name. We eventually decided to omit any reference to the word "hardware" after this comment. And so we ended up withavailable_concurrency
instead.For a talk I was preparing this week I was reading through "Understanding and expressing scalable concurrency" (A. Turon, 2013), and the following passage stood out to me (emphasis mine):
Chapter 2.1: Concurrency is not Parallelism. Page 30.
"Concurrency is a system-structuring mechanism. Parallelism is a resource." — It feels like this accurately captures the way we should be thinking about these APIs. What this API returns is not "the amount of concurrency available to the program" which is a property of the program, and thus even with just a single thread is effectively unbounded. But instead it returns "the amount of parallelism available to the program", which is a resource hard-constrained by the machine's capacity (and can be further restricted by e.g. operating systems).
That's why I'd like to propose we rename this API from
available_concurrency
toavailable_parallelism
. This still meets the criteria we previously established of not attempting to define what exactly we mean by "hardware", "threads", and other such words. Instead we only talk about "concurrency" as an abstract resource available to our program.r? @joshtriplett