Repository navigation
Use pthread_cpu_number_np for current processor number when sched_getcpu is unavailable (macOS) - #137231
Merged
Conversation
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @VSadov |
Co-authored-by: VSadov <[email protected]>
Copilot
AI
changed the title
[WIP] Use pthread_cpu_number_np to get current core on OSX
Use pthread_cpu_number_np for current processor number when sched_getcpu is unavailable (macOS)
Nov 10, 2026
Co-authored-by: VSadov <[email protected]>
…ead affinity support too Co-authored-by: VSadov <[email protected]>
Contributor
|
Tagging subscribers to this area: @anicka-net, @dotnet/gc |
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @VSadov |
3 tasks
VSadov
marked this pull request as ready for review
November 10, 2026 23:12
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.

Thread.GetCurrentProcessorId()and the GC's per-processor logic get no processor number on macOS, becausesched_getcpudoesn't exist there.pthread_cpu_number_npis available on all supported macOS versions, so use it as the fallback.src/native/libs/configure.cmake(pal_config.h.in):HAVE_PTHREAD_CPU_NUMBER_NPviacheck_symbol_existson<pthread.h>.src/coreclr/gc/unix/configure.cmake(config.gc.h.in): the same macro via a compile check.SystemNative_SchedGetCpu,pal_threading.c): thesched_getcpupath is unchanged. The new#elifbranch callspthread_cpu_number_np, and the shim returns -1 on failure or when neither API exists, soProcessorIdCachestill falls back to the managed thread ID.gcenv.unix.cpp):GetCurrentProcessorNumber()usespthread_cpu_number_npwhensched_getcpuis unavailable.CanGetCurrentProcessorNumber()now returns true when either API is present, so the GC's processor-number code paths are newly enabled on macOS.Thread.Unix.csandProcessorIdCache.csto mention both APIs.Not built or run on macOS. The new path depends on the SDK declaring
pthread_cpu_number_npin<pthread.h>. If it doesn't, the check fails quietly and macOS keeps returning -1, so please confirmHAVE_PTHREAD_CPU_NUMBER_NPis set in a macOS build.