Skip to content

setcore: avoid infinite loop when core pinning always fails (#103)#116

Open
rdicosmo wants to merge 1 commit into
masterfrom
fix/103-no-infinite-loop-on-pinning-failure
Open

setcore: avoid infinite loop when core pinning always fails (#103)#116
rdicosmo wants to merge 1 commit into
masterfrom
fix/103-no-infinite-loop-on-pinning-failure

Conversation

@rdicosmo
Copy link
Copy Markdown
Owner

Summary

  • Bound the setcore retry loop so a permanent core-pinning failure no longer hangs the worker.
  • Pure logic change (while (finished==0)do { … } while (finished==0 && w>0)); no refactoring, no whitespace noise.

Context

setcore halves w every time the OS rejects the affinity request. On platforms where pinning to core 0 also fails (observed on Apple M1 / Homebrew), w reaches 0 and the unbounded loop spins forever — see #103, semgrep/semgrep#2432, facebook/infer#1410.

Original analysis and patch by @IagoAbal in #104; this PR carries just the logic change he was asked to extract back in 2021. PR #104 can be closed in favor of this.

Test plan

  • dune build @install passes locally (Linux x86_64, OCaml 5).
  • dune runtest passes locally (full suite, including simplescale* and floatscale).
  • Re-confirmation on Apple M1 that the previously-hanging input no longer hangs (cannot test from this machine).

Closes #103.

🤖 Generated with Claude Code

If sched_setaffinity / thread_policy_set keeps failing, w is repeatedly
halved and eventually reaches 0; on systems where pinning to core 0 also
fails the previous unbounded `while (finished==0)` loop never terminates
(observed on Apple M1 / Homebrew, see #103).

Bound the retry loop with `w>0` so a permanent failure surfaces by
returning rather than hanging the worker. Logic only — no refactor.

Original analysis and patch by IagoAbal in #104.

Closes #103

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Infinite loop if core pinning fails

1 participant