Skip to content

Commit 4b84df9

Browse files
committed
std::thread: refine available_parallelism for solaris/illumos.
Rather than the system-wide available cpus fallback solution, we fetch the cpus bound to the current process.
1 parent 548e14b commit 4b84df9

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

library/std/src/sys/pal/unix/thread.rs

+6
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,12 @@ pub fn available_parallelism() -> io::Result<NonZero<usize>> {
483483
.ok_or(io::const_io_error!(io::ErrorKind::NotFound, "The number of hardware threads is not known for the target platform"))
484484
}
485485
}
486+
} else if #[cfg(any(target_os = "solaris", target_os = "illumos"))] {
487+
let mut cpus = 0u32;
488+
if unsafe { libc::pset_info(libc::PS_MYID, core::ptr::null_mut(), &mut cpus, core::ptr::null_mut()) } == 0 {
489+
NonZero::new(cpus as usize)
490+
.ok_or(io::const_io_error!(io::ErrorKind::NotFound, "The number of hardware threads is not known for the target platform"))
491+
}
486492
} else if #[cfg(target_os = "haiku")] {
487493
// system_info cpu_count field gets the static data set at boot time with `smp_set_num_cpus`
488494
// `get_system_info` calls then `smp_get_num_cpus`

0 commit comments

Comments
 (0)