【问题标题】:Is it possible to set pthread CPU affinity in OS X?是否可以在 OS X 中设置 pthread CPU 亲和性?
【发布时间】:2015-09-16 08:19:30
【问题描述】:

Linux 中有一个 sched_setaffinity() 函数定义在 sched.h 中,但我似乎找不到类似的东西在 Mac OS X 10.6 pthreads 实现中...如果无法设置关联,OS X 中的默认策略是什么?

【问题讨论】:

标签: linux multithreading macos pthreads affinity


【解决方案1】:

Mac OS X 有 Thread Affinity API,您可以将它与 pthread ID 一起使用,如 thread_policy_set(pthread_mach_thread_np(pthreadId),但据我所知,没有像 sched_setaffinity 这样的 API。

【讨论】:

  • 什么鬼?我查看了 Mac OS X 10.6 SDK 的 /usr/include/mach/thread_policy.h 并发现 thread_policy_set() / thread_policy_get() 函数被注释掉了!这是什么意思?!
  • 确实兼容pthread。请查看 /Developer/Extras/CoreAudio/PublicUtility/CAPThread.cpp 或谷歌“thread_policy_set pthread_mach_thread_np”。而 thread_policy_set/thread_policy_get 位于 /Developer/SDKs/MacOSX10.6.sdk/usr/include/mach/x86_64/thread_act.h 中。无论如何,这些 API 与 sched_setaffinity 不同。
猜你喜欢
  • 2010-11-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-20
  • 1970-01-01
  • 2014-08-30
  • 1970-01-01
相关资源
最近更新 更多