Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic when encountering an illegal cpumask in thread::available_parallelism #115946

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions library/std/src/sys/unix/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,10 @@ pub fn available_parallelism() -> io::Result<NonZeroUsize> {
if libc::sched_getaffinity(0, mem::size_of::<libc::cpu_set_t>(), &mut set) == 0 {
let count = libc::CPU_COUNT(&set) as usize;
let count = count.min(quota);
// SAFETY: affinity mask can't be empty and the quota gets clamped to a minimum of 1
return Ok(NonZeroUsize::new_unchecked(count));
// reported to occur on MIPS kernels older than our minimum supported kernel version for those targets
let count = NonZeroUsize::new(count)
.expect("CPU count must be > 0. This may be a bug in sched_getaffinity(); try upgrading the kernel.");
return Ok(count);
}
}
}
Expand Down