#include <Windows.h>
#include<stdio.h>
HANDLE g_hThreadEvent;
DWORD WINAPI ThreadProc(LPVOID lpParam)
{
for (int i = 0; i <10; i++)
{
printf("threadid:%d num:%d
", GetCurrentThreadId(), i);
}
SetEvent(g_hThreadEvent);
return 0;
}
int main(int argc, char *argv[])
{
g_hThreadEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
for (int i = 0; i < 50; i++)
{
CreateThread(NULL, 0, ThreadProc, NULL, NULL, nullptr);
WaitForSingleObject(g_hThreadEvent, INFINITE);
for (int j = 0; j < 100; j++)
{
printf_s("threadid: %d xh:%d num:%d
", GetCurrentThreadId(), i, j);
}
ResetEvent(g_hThreadEvent);
}
CloseHandle(g_hThreadEvent);
system("pause");
return 0;
}