setcore: avoid infinite loop when core pinning always fails (#103)#116
Open
rdicosmo wants to merge 1 commit into
Open
setcore: avoid infinite loop when core pinning always fails (#103)#116rdicosmo wants to merge 1 commit into
rdicosmo wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
setcoreretry loop so a permanent core-pinning failure no longer hangs the worker.while (finished==0)→do { … } while (finished==0 && w>0)); no refactoring, no whitespace noise.Context
setcorehalveswevery time the OS rejects the affinity request. On platforms where pinning to core 0 also fails (observed on Apple M1 / Homebrew),wreaches 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 @installpasses locally (Linux x86_64, OCaml 5).dune runtestpasses locally (full suite, includingsimplescale*andfloatscale).Closes #103.
🤖 Generated with Claude Code