Obtaining thread Core affinity in C++ 11 through pthreads

后端 未结 2 1500
庸人自扰
庸人自扰 2021-02-06 04:44

I\'m trying to set core affinity (Thread #1 goes on first core, Thread #2 goes on second core, ...) while using std::thread in C++ 11.

I\'ve already searched around vari

相关标签:
2条回答
  • 2021-02-06 05:25

    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.

    0 讨论(0)
  • 2021-02-06 05:30

    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.

    0 讨论(0)
提交回复
热议问题