Skip to content
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

Merged
merged 2 commits into from
Oct 6, 2021
Merged

Rename std::thread::available_conccurrency to std::thread::available_parallelism #89324

merged 2 commits into from
Oct 6, 2021

Conversation

yoshuawuyts
Copy link
Member

@yoshuawuyts yoshuawuyts commented Sep 28, 2021

Tracking issue: #74479

This PR renames std::thread::available_conccurrency to std::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 with available_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):

Concurrency is a system-structuring mechanism. An interactive system that deals with disparate asynchronous events is naturally structured by division into concurrent threads with disparate responsibilities. Doing so creates a better fit between problem and solution, and can also decrease the average latency of the system by preventing long-running computations from obstructing quicker ones.

Parallelism is a resource. A given machine provides a certain capacity for parallelism, i.e., a bound on the number of computations it can perform simultaneously. The goal is to maximize throughput by intelligently using this resource. For interactive systems, parallelism can decrease latency as well.

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 to available_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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 28, 2021
@joshtriplett
Copy link
Member

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.

@camsteffen
Copy link
Contributor

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.

@joshtriplett joshtriplett added S-waiting-on-bikeshed Status: Awaiting a decision on trivial things. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 4, 2021
@joshtriplett
Copy link
Member

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 hardware_concurrency (for C++ folks) and available_concurrency (for folks who search and find references to the previous name)?

@joshtriplett
Copy link
Member

@rfcbot merge

@rfcbot
Copy link

rfcbot commented Oct 4, 2021

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.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Oct 4, 2021
@yoshuawuyts
Copy link
Member Author

Would you consider also adding doc aliases for both hardware_concurrency (for C++ folks) and available_concurrency (for folks who search and find references to the previous name)?

Ah yeah, good call. Pushed!

@BurntSushi
Copy link
Member

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.

@rfcbot rfcbot added the final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. label Oct 5, 2021
@rfcbot
Copy link

rfcbot commented Oct 5, 2021

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot rfcbot removed the proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. label Oct 5, 2021
@yoshuawuyts
Copy link
Member Author

I do think it would be nice to perhaps mention the word hardware or "CPU" in the docs somewhere.

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.

@m-ou-se
Copy link
Member

m-ou-se commented Oct 6, 2021

@bors r+

@bors
Copy link
Contributor

bors commented Oct 6, 2021

📌 Commit 03fbc16 has been approved by m-ou-se

@bors
Copy link
Contributor

bors commented Oct 6, 2021

🌲 The tree is currently closed for pull requests below priority 100. This pull request will be tested once the tree is reopened.

@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Oct 6, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 6, 2021
…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
@bors bors merged commit b4615b5 into rust-lang:master Oct 6, 2021
@rustbot rustbot added this to the 1.57.0 milestone Oct 6, 2021
@yoshuawuyts yoshuawuyts deleted the hardware-parallelism branch October 6, 2021 23:27
@Thomasdezeeuw
Copy link
Contributor

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 available_conccurrency was gone, not knowing it was renamed.

@yaahc
Copy link
Member

yaahc commented Oct 11, 2021

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 available_conccurrency was gone, not knowing it was renamed.

👍. I've gone ahead and nominated this suggestion for discussion during the next libs team meeting this Wednesday.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 13, 2021
…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`
@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. to-announce Announce this issue on triage meeting and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Oct 15, 2021
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Oct 21, 2021
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 30, 2021
…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.
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 4, 2021
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. S-waiting-on-bikeshed Status: Awaiting a decision on trivial things. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.