]> git.lizzy.rs Git - rust.git/commit - src/tools/miri
Rollup merge of #89324 - yoshuawuyts:hardware-parallelism, r=m-ou-se
authorManish Goregaokar <manishsmail@gmail.com>
Wed, 6 Oct 2021 19:33:17 +0000 (12:33 -0700)
committerGitHub <noreply@github.com>
Wed, 6 Oct 2021 19:33:17 +0000 (12:33 -0700)
commitb4615b5bf9e3e722b480190714ad44ecd7fa2ed1
tree0def5076a01f2efeac8425bee03e7f6cd7ae22b4
parent14da7fc9aecd3db114441ba2f0320c75cd066d77
parent03fbc160cd79556f9b99c37c2580e3da9826c432
Rollup merge of #89324 - yoshuawuyts:hardware-parallelism, r=m-ou-se

Rename `std::thread::available_conccurrency` to `std::thread::available_parallelism`

_Tracking issue: https://github.com/rust-lang/rust/issues/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](https://en.cppreference.com/w/cpp/thread/thread/hardware_concurrency). We eventually decided to omit any reference to the word "hardware" after [this comment](https://github.com/rust-lang/rust/pull/74480#issuecomment-662045841). 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)](http://aturon.github.io/academic/turon-thesis.pdf), 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`
library/std/src/sys/unix/thread.rs
library/std/src/thread/mod.rs