From be028948f45e8b67cce7de56fe6c9dc9b6d5b270 Mon Sep 17 00:00:00 2001 From: Vistawizard <60033971+Vistawizard@users.noreply.github.com> Date: Sat, 26 Sep 2026 19:23:15 +0200 Subject: [PATCH] CPU pool: fix dangling else in the Linux physical_cores() branch Without braces the `else` bound to `if (CPU_ISSET(i, &set))`, so every CPU id outside the affinity mask appended all hardware_concurrency() ids again: 16143 pool workers on a 16-CPU box, load > 10000 and a hang at start. Brace both branches so the fallback only runs when sched_getaffinity fails. Fixes #13, root cause of #11. --- src/kernels/cpu/pool.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/kernels/cpu/pool.cpp b/src/kernels/cpu/pool.cpp index 2b963ad0..dfbb9de4 100644 --- a/src/kernels/cpu/pool.cpp +++ b/src/kernels/cpu/pool.cpp @@ -49,11 +49,12 @@ std::vector physical_cores(bool skip_first) { #else cpu_set_t set; CPU_ZERO(&set); - if (sched_getaffinity(0, sizeof set, &set) == 0) + if (sched_getaffinity(0, sizeof set, &set) == 0) { for (int i = 0; i < CPU_SETSIZE; ++i) if (CPU_ISSET(i, &set)) cores.push_back(i); - else + } else { for (unsigned i = 0; i < std::thread::hardware_concurrency(); ++i) cores.push_back((int) i); + } #endif if (skip_first && !cores.empty()) cores.erase(cores.begin()); return cores;