DWORD WINAPI ThreadProc(LPVOID pParam)
{
CString s;
s.Format(L"Thread %d finished\r\n", pParam);
OutputDebugString(s);
return 0; // thread completed successfully
}
const int num = 4;
HANDLE g_h[num];
void OnTest()
{
for (int i = 0; i < num; i++)
{
DWORD id;
g_h[i] = CreateThread(NULL, 0, ThreadProc, (LPVOID)i, CREATE_SUSPENDED, &id);
ResumeThread(g_h[i]);
}
WaitForMultipleObjects(num, g_h, TRUE, INFINITE);
}