Obtaining thread Core affinity in C++ 11 through pthreads

半世苍凉 提交于 2019-12-03 03:16:13

You can get the native handle for the thread with the native_handle function.

The example in the linked reference even uses this to call pthread functions.

I do not know if it is a suitable approach in your case, but what I usually do is to call the affinity primitives from within the thread. E.g., I place a snippet of code similar to this one somewhere at the beginning of the threaded function:

const int err = pthread_setaffinity_np(pthread_self(),...);

The call to pthread_self() will return the ID of the calling thread.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!