0
我想了解在HT系統中創建pthreads時,什麼是默認親和力政策,其次是科學Linux內核2.6.32。有沒有辦法知道它?在pthreads的創建中,不存在對關聯的調用,所以我認爲親和力留給了操作系統。找出違反pthread親和力政策,然後Linux內核2.6.32
我想了解在HT系統中創建pthreads時,什麼是默認親和力政策,其次是科學Linux內核2.6.32。有沒有辦法知道它?在pthreads的創建中,不存在對關聯的調用,所以我認爲親和力留給了操作系統。找出違反pthread親和力政策,然後Linux內核2.6.32
不知道這是有益的,但這裏是一些代碼,將獲得和使用並行線程API設置線程的親和力:
// nail down this thread so it will only run on a specific CPU
cpu_set_t tCPUSet;
CPU_ZERO(&tCPUSet);
CPU_SET(ENCODE_LEFT_THREAD_CPU, &tCPUSet);
nReturnCode = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &tCPUSet);
if (nReturnCode == -1) {
pLogFile->Write(LOG_ERR, "ERROR: encodeLeftThread(): pthread_setaffinity() failed, %s, exiting thread... ", strerror(errno));
nThreadReturnValue = THREAD_CPU_AFFINITY_ERRORS;
pthread_exit((void *)&nThreadReturnValue);
}
CPU_ZERO(&tCPUSet);
nReturnCode = pthread_getaffinity_np(pthread_self(), sizeof(cpu_set_t), &tCPUSet);
if (nReturnCode == -1) {
pLogFile->Write(LOG_ERR, "ERROR: encodeLeftThread(): 2nd pthread_getaffinity() failed, %s, exiting thread... ", strerror(errno));
nThreadReturnValue = THREAD_CPU_AFFINITY_ERRORS;
pthread_exit((void *)&nThreadReturnValue);
}
sCPUs.clear();
sCPUs.append(" new left thread CPU affinity: ");
if (bInitLog) {
for (int i = 0; i < CPU_SETSIZE; i++) {
if (CPU_ISSET(i, &tCPUSet)) {
sCPUs.append(" ");
char c = '0' + i;
sCPUs = sCPUs + c;
}
}
}
if (bInitLog) pLogFile->Write(LOG_DEBUG, "%s ", sCPUs.c_str());
@安德烈斯·岡薩雷斯謝謝你,這是絕對有用的 – Manolete