Skip to content

Commit aa04667

Browse files
committed
std library thread.rs: undo attempt at NetBSD-specific "find parallelism".
First off, I have it on good authority this code is Just Wrong: by default a given thread does not have affinity to any specific set of CPUs. This particular change came with this pull request: rust-lang#112226 However, even worse, this code causes a segmentation fault for certain NetBSD target architectures in the "bootstrap" program when building rust natively on those platforms. So far armv7/9.0, powerpc/10.0_BETA, and i386/9.3 all crash with a segmentation fault. However, for some strange reason, this isn't consistent across the board: riscv64/current, amd64/10.0_BETA, aarch64/9.0 and sparc64/10.0_BETA all pass this hurdle. A trivial C reimplementation also doesn't crash on any of these systems, ref. the thread which starts at https://mail-index.netbsd.org/current-users/2023/10/10/msg044510.html but also always prints 0. However, if we get a SEGV running this code, the entire build fails, of course. So ... while I do not have a full explanation for the SEGVs, this undoes the addition from pull request 112226, and restores the ability to build rust natively on the above flagged-as-problematical platforms.
1 parent 3ff244b commit aa04667

File tree

1 file changed

+0
-23
lines changed

1 file changed

+0
-23
lines changed

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

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -375,29 +375,6 @@ pub fn available_parallelism() -> io::Result<NonZeroUsize> {
375375
}
376376
}
377377

378-
#[cfg(target_os = "netbsd")]
379-
{
380-
unsafe {
381-
let set = libc::_cpuset_create();
382-
if !set.is_null() {
383-
let mut count: usize = 0;
384-
if libc::pthread_getaffinity_np(libc::pthread_self(), libc::_cpuset_size(set), set) == 0 {
385-
for i in 0..u64::MAX {
386-
match libc::_cpuset_isset(i, set) {
387-
-1 => break,
388-
0 => continue,
389-
_ => count = count + 1,
390-
}
391-
}
392-
}
393-
libc::_cpuset_destroy(set);
394-
if let Some(count) = NonZeroUsize::new(count) {
395-
return Ok(count);
396-
}
397-
}
398-
}
399-
}
400-
401378
let mut cpus: libc::c_uint = 0;
402379
let mut cpus_size = crate::mem::size_of_val(&cpus);
403380

0 commit comments

Comments
 (0)