2024年4月28日发(作者:)

DWORD start = GetTickCount();

//初始化临界区

InitializeCriticalSection(&cs);

//多线程扫描

HANDLE hThread[THREADCOUNT];

for (int i=0;i

{

hThread[i] = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)ThreadProc,(LPVOID)0,0,NULL);

}

//当thread数量超过64的处理

int tempNumThreads = THREADCOUNT;

int tempMax = 0;

while( tempNumThreads >= MAXIMUM_WAIT_OBJECTS )

{

tempNumThreads -= MAXIMUM_WAIT_OBJECTS;

WaitForMultipleObjects( MAXIMUM_WAIT_OBJECTS, &hThread[ tempMax ], false, INFINITE);

tempMax += MAXIMUM_WAIT_OBJECTS;

}

WaitForMultipleObjects( tempNumThreads, &hThread[ tempMax ], false, INFINITE);

//删除临界区

DeleteCriticalSection(&cs);

DWORD end = GetTickCount();

printf("use time(s):%fn", (end-start)/1000.0);

system("pause");

return 0;

}