15,471
社区成员
发帖
与我相关
我的任务
分享
unsigned int __stdcall test(void* lparam)
{
return 1;
}
int main()
{
uintptr_t test_thread1 = _beginthreadex(NULL, 0, &test, NULL, CREATE_SUSPENDED, NULL);
uintptr_t test_thread2 = _beginthreadex(NULL, 0, &test, NULL, CREATE_SUSPENDED, NULL);
HANDLE wait_handle[2] = {0};
wait_handle[0] = (HANDLE)test_thread1;
wait_handle[1] = (HANDLE)test_thread2;
while (true)
{
DWORD ret = WaitForMultipleObjects(2, wait_handle, TRUE, 100);
switch (ret)
{
case WAIT_FAILED:
cout << "failed, error_code:" << GetLastError() << endl;
break;
case WAIT_TIMEOUT:
cout << "timeout" << endl;
ResumeThread(wait_handle[0]);
ResumeThread(wait_handle[1]);
break;
case WAIT_OBJECT_0:
cout << "obj 0" << endl;
CloseHandle(wait_handle[0]);
break;
case WAIT_OBJECT_0 + 1:
cout << "obj 1" << endl;
CloseHandle(wait_handle[1]);
break;
default:
break;
}
}
return 1;
}