2
我試圖改變啓動程序內每個線程的親和力。Pthread_setaffinity_np無效的參數
這是代碼。在下面的代碼中,'t'是通過pthread_create函數傳遞的參數。
cpu_set_t mask;
pthread_t c;
a = *((int *)t);
printf(" thread no. is %d \n",a);
CPU_ZERO(&mask);
a =a/2 + 1;
CPU_SET(a,&mask);
c=pthread_self();
s=pthread_setaffinity_np(c,sizeof(cpu_set_t), &mask);
if (s!=0)
handle_error_en(s,"pthread_setaffinity_np");
線程關聯沒有得到改變。我哪裏錯了?
順便說一句,你可以用'CPU_SET((a/2 + 1),&mask);'替代整個switch語句 – 2012-01-16 21:57:05
Ohh謝謝...... P – akhil28288 2012-01-16 21:59:30
也許更好一點,可以肯定它只被評估一次, a = a/2 + 1; CPU_SET(a,&mask);'。 – 2012-01-16 22:05:30