Set process affinity upon match start.#924
Merged
Disservin merged 3 commits intoDisservin:masterfrom Sep 28, 2025
Merged
Conversation
JoostHouben
commented
Sep 28, 2025
Owner
|
thanks! |
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.
Fixes #922.
The previous approach has a couple of issues:
setAffinityfunction (as written) on Windows only works for setting process affinity, not for setting thread affinity. For thread affinity, a different set of Windows APIs needs to be used. However, the function is used for setting thread affinity (inBaseTournament::playGame).BaseTournament::playGame, the return code ofsetAffinitywas not checked, so even though this call always fails on Windows, the failure was ignored.In other words: the logic from #867 simply doesn't apply to Windows. The logic there assumes the Linux model of affinities, where (IIUC) affinity is a thread-level property, processes only have an affinity insofar as their main thread does, and threads inherit their affinity from parent threads, even across process boundaries.
In this PR I fix this by:
setAffinityintosetThreadAffinityandsetProcessAffinityso that semantics on different platforms can be correctly represented. On Linux,setProcessAffinitycan simply callsetThreadAffinity, which will set the affinity of the process's main thread (the existing behavior).UciEngine::start. On Linux this shouldn't have any effect if the tournament's thread affinity is already set.BaseTournament::playGameso that failure to set thread affinity isn't silently ignoredaffinity::functions[[nodiscard]]Additionally, the Makefile is modified to use static linking on Windows for debug builds. It might just be how my environment is set up, but when building in debug mode (with msys2 and ucrt64), I wasn't able to run the resulting binary because it couldn't find the required DLLs. Making the build static fixes this problem, making debugging easier. Note that under release we always produce a statically linked binary regardless.
Testing done: