Skip to content

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

Open
@Fulgen301

Description

@Fulgen301

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

pub fn available_parallelism() -> io::Result<NonZero<usize>> {
let res = unsafe {
let mut sysinfo: c::SYSTEM_INFO = crate::mem::zeroed();
c::GetSystemInfo(&mut sysinfo);
sysinfo.dwNumberOfProcessors as usize
};
match res {
0 => Err(io::Error::UNKNOWN_THREAD_COUNT),
cpus => Ok(unsafe { NonZero::new_unchecked(cpus) }),
}
}

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-threadArea: `std::thread`C-enhancementCategory: An issue proposing an enhancement or a PR with one.O-windowsOperating system: WindowsT-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions