Is it possible to set pthread CPU affinity in OS X?
Asked Answered
H

1

6

In Linux there is a sched_setaffinity() function defined in sched.h, but I can't seem to find anything like that in Mac OS X 10.6 pthreads implementation... If it is not possible to set affinity, what is the default policy in OS X?

Hamite answered 31/5, 2011 at 6:42 Comment(1)
See this blog: yyshen.github.io/2015/01/18/binding_threads_to_cores_osx.htmlWesternism
G
6

Mac OS X has Thread Affinity API and you can use it with pthread ID as thread_policy_set(pthread_mach_thread_np(pthreadId), but, as far as I know, there are no APIs like sched_setaffinity.

Golfer answered 31/5, 2011 at 7:31 Comment(2)
What the hell? I took a look at Mac OS X 10.6 SDK's /usr/include/mach/thread_policy.h and found out that the thread_policy_set() / thread_policy_get() functions are commented out! What is the meaning of this?!Hamite
It is really compatible with pthread. Please take a look at /Developer/Extras/CoreAudio/PublicUtility/CAPThread.cpp or google "thread_policy_set pthread_mach_thread_np". And thread_policy_set/thread_policy_get are in /Developer/SDKs/MacOSX10.6.sdk/usr/include/mach/x86_64/thread_act.h . Anyway, these API are not same as sched_setaffinity.Golfer

© 2022 - 2024 — McMap. All rights reserved.