Closed
Description
The feature gate for the issue is #![feature(available_parallelism)]
.
This is a tracking issue for std::thread::available_parallelism
; a portable API to determine how many threads to spawn in order to ensure a program can make use of all available parallelism available on a machine.
Public API
#![feature(available_parallelism)]
use std::thread;
fn main() -> std::io::Result<()> {
let count = thread::available_parallelism()?.get();
assert!(count >= 1);
Ok(())
}
Tasks
- Resolve discussion on naming.
- Resolve discussion on function signature.
- Resolve discussion on terminology.
- Add support for externally-set limits on Linux (ref).
- Add support for externally-set limits on Windows (ref).
- Update documentation to remove mentions of "hardware" (ref).
- Smooth out the docs example.
Notes on Platform-specific behavior
available_parallelism
is (for now) only considered a hint. The following platform limitations exist:
- On Windows the available concurrency may be undercounted when exceeding 64 threads Add
std::thread::available_concurrency
#74480 (comment) - On Windows the available concurrency may be overcounted when limited by a process wide affinity mask or job object limitations Add
std::thread::available_concurrency
#74480 (comment) - On Linux the available concurrency may be overcounted in the face of cgroup limits and task-wise affinity masks Add
std::thread::available_concurrency
#74480 (comment)
Implementation history
- Add
std::thread::available_concurrency
#74480 - Move
available_concurrency
implementation tosys
#85182 - Make
std::thread::available_concurrency
support process-limited number of CPUs #89310 - Rename
std::thread::available_conccurrency
tostd::thread::available_parallelism
#89324 - Use cgroup quotas for calculating
available_parallelism
#92697 - Add cgroupv1 support to available_parallelism #97925
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Metadata
Assignees
Labels
Area: ConcurrencyBlocker: Implemented in the nightly compiler and unstable.Category: A tracking issue for an RFC or an unstable feature.Libs issues that are considered "small" or self-containedLibs issues that are tracked on the team's project board.Relevant to the library API team, which will review and decide on the PR/issue.This issue / PR is in PFCP or FCP with a disposition to merge it.The final comment period is finished for this PR / Issue.