多核编程与并行计算
}
int i; DWORD ThreadID[THREAD_INSTANCE_NUMBER]; HANDLE hSemaphore; if ((hSemaphore = CreateSemaphore(NULL,0,1, "Semaphore.Test")) == NULL ) { } cout << "Create Semaphore error!" << endl; return 0; HANDLE hThread[THREAD_INSTANCE_NUMBER]; for (i=0;i<THREAD_INSTANCE_NUMBER;i++) { } WaitForMultipleObjects(THREAD_INSTANCE_NUMBER,hThread,TRUE,INFINITE); cout << "Close the Semaphore Handle! " << endl; CloseHandle(hSemaphore); return 0; hThread[i] = CreateThread(NULL, if (hThread[i] == NULL) cout << "CreateThread error" << ThreadID[i] << endl; cout << "CreateThread: " << ThreadID[i] << endl; 0, (LPTHREAD_START_ROUTINE) foo, (void *)&ThreadID[i], 0, &(ThreadID[i])); else