WaitForMultipleObjects
The WaitForMultipleObjects function returns when one of the following occurs:
- Either any one or all of the specified objects are in the signaled state.
- The time-out interval elapses.
DWORD WaitForMultipleObjects(
DWORD nCount, // number of handles in the handle array
CONST HANDLE *lpHandles, // pointer to the object-handle array
BOOL fWaitAll, // wait flag
DWORD dwMilliseconds // time-out interval in milliseconds
);
实例:
WSAEVENT wsaevt1=WSACreateEvent();
WSAEVENT wsaevt2=WSACreateEvent();
HANDLE lpHandles[2];
lpHandles[0]=wsaevt1;
lpHandles[1]=wsaevt2;
while(1)
{
DWORD rc=WaitForMultipleObjects(2,lpHandles,FALSE,INFINITE);
if(rc==WSA_WAIT_FAILED)
{
break;
}
else if (rc==WAIT_OBJECT_0)
{
break;
}
//do something
}
多线程程序中一般都有用到这个函数。