-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Open
Labels
A-threadArea: `std::thread`Area: `std::thread`C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.O-windowsOperating system: WindowsOperating system: WindowsT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Description
Currently, the Windows implementation of std::thread::available_parallelism
just returns the number of CPUs on the system:
rust/library/std/src/sys/pal/windows/thread.rs
Lines 126 to 136 in e3fccdd
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
Labels
A-threadArea: `std::thread`Area: `std::thread`C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.O-windowsOperating system: WindowsOperating system: WindowsT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.