저는 Linux Centos를 사용하고 있습니다. 내가이 set_affinity를 사용할 때Linux의 pthread에서 사용 가능한 물리적 CPU 코어 사용
내가 pthread 같은 C 코딩 및 pthread_set_affinity .I를 사용하여 독특한 processor.Like에서 실행하는 각 스레드를보고 싶어하고 ---
thread1 in proccessor 0
thread2 in proccessor 1
.
.
.
threadn in processor n
현재는 실행되지만 때 나는 시스템 모니터가 8 코어의 CPU 사용이 분산되어있는 것을 보았습니다.
코드는 ::
if(for thread 1)
{
pthread_attr_init(&pta);
CPU_SET(0,&cpuset);
pthread_setaffinity_np(thread1, sizeof(cpu_set_t), &cpuset);
pthread_create(&thread1,&pta,&sendimsg,(void*)&message);
pthread_join(thread1,NULL);
printf("User for Thread One : %d\n",numb.fir);
pthread_attr_destroy(&pta);
CPU_ZERO(&cpuset);
}
else if(for thread 2)
{
pthread_attr_init(&pra);
CPU_SET(1,&cpuset1);
pthread_setaffinity_np(thread2, sizeof(cpu_set_t), &cpuset);
pthread_create(&thread2,&pra,&sendimsg,(void*)&message);
pthread_join(thread2,NULL);
printf("User for Thread Two : %d\n",numb.sec);
pthread_attr_destroy(&pra);
CPU_ZERO(&cpuset1);
}
for eight thread that way.
참고 같다 : 스레드가 20 20 20 20처럼에 분산 할당 ... 비율이 그런 식으로
10 %와 같은 20
1 0 % 2 % 0 % 1 % 0 % 0 % 1 %
저는 8 개의 코어 PC를 가지고 있고 8 코어에서 8 개의 스레드를 실행하려고합니다.이 pthread와 p에서 8 코어를 완전하게 활용할 수있는 방법이 있습니까? thread_set_affinity.
일부 스레드는 CPU 사용량이 많으며 일부 스레드는 차단 된 IO 호출을 기다리면서 뮤텍스 잠금을 대기 또는 대기 중일 수 있습니다. –
어쩌면 코드를 보여줄 수 있습니다. 그러면 누군가가 일반 가정보다 더 많은 것을 도와 줄 수 있습니다. –
스레드가 그 스레드 사이에 공통 데이터를 사용하는 경우 실제로는 그리 좋은 생각이 아닐 수도 있습니다. 그 이유는 그 데이터가 모든 캐시가 아닌 캐시간에 복사되어야하기 때문입니다. –