Obtaining thread Core affinity in C++ 11 through pthreads

后端 未结 2 1501
庸人自扰
庸人自扰 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.

提交回复
热议问题