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?
Is it possible to set pthread CPU affinity in OS X?
See this blog: yyshen.github.io/2015/01/18/binding_threads_to_cores_osx.html –
Westernism
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.
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.