rust-lang / rust-lang/rust

`std::thread::available_parallelism` should respect process affinity and job object limitations

Open
#143,709 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-thread C-enhancement O-windows T-libs
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Currently, the Windows implementation of std::thread::available_parallelism just returns the number of CPUs on the system:

https://github.com/rust-lang/rust/blob/e3fccdd4a16bf3aa223749efef1fa981589e43ae/library/std/src/sys/pal/windows/thread.rs#L126-L136

This is in stark contrast to the Linux implementation, which not only checks process affinity, but also queries cgroup information. It'd be better if the Windows implementation also respected process affinity and job object limitations.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in library/std/src/sys/pal/windows/thread.rs at the linked available_parallelism implementation, then compare it with the Linux implementation's handling of process affinity and cgroup information. Investigate the Windows APIs needed to account for process affinity and job object limitations. Done means the Windows result reflects those constraints rather than only the system CPU count.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.