当前位置: 技术问答>linux和unix
如何确定 pthread 双线程是在两个核上运行,而不是在一个核(超核)上运行
来源: 互联网 发布时间:2017-02-25
本文导语: RT,是否有神马控制语句 | In the following program, the main thread uses pthread_setaffinity_np() to set its CPU affinity mask to include CPUs 0 to 7 (which may not all be avail- able on the system),...
RT,是否有神马控制语句
|
In the following program, the main thread uses pthread_setaffinity_np() to set its CPU affinity mask to include CPUs 0 to 7 (which may not all be avail-
able on the system), and then calls pthread_getaffinity_np() to check the resulting CPU affinity mask of the thread.
#define _GNU_SOURCE
#include
#include
#include
#include
#define handle_error_en(en, msg)
do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0)
int
main(int argc, char *argv[])
{
int s, j;
cpu_set_t cpuset;
pthread_t thread;
thread = pthread_self();
/* Set affinity mask to include CPUs 0 to 7 */
CPU_ZERO(&cpuset);
for (j = 0; j