等待超过64个线程
等待超过64个线程
#include <afxwin.h> DWORD SyncWaitForMultipleObjs(HANDLE * handles, size_t count) { int waitingThreadsCount = count; int index = 0; DWORD res = 0; while(waitingThreadsCount >= MAXIMUM_WAIT_OBJECTS) { res = WaitForMultipleObjects(MAXIMUM_WAIT_OBJECTS, &handles[index], TRUE, INFINITE); if(res == WAIT_TIMEOUT || res == WAIT_FAILED) { puts("1. Wait Failed."); return res; } waitingThreadsCount -= MAXIMUM_WAIT_OBJECTS; index += MAXIMUM_WAIT_OBJECTS; } if(waitingThreadsCount > 0) { res = WaitForMultipleObjects(waitingThreadsCount, &handles[index], TRUE, INFINITE); if(res == WAIT_TIMEOUT || res == WAIT_FAILED) { puts("2. Wait Failed."); } } return res; }

浙公网安备 33010602011771号