http://blog.youkuaiyun.com/wangweitingaabbcc/article/details/7904878
do
{
dwWait = MsgWaitForMultipleObjects(1, //[in]nCount
&hThread, //[in]pHandles
FALSE, //[in]bWaitAll
5000, //[in]dwMilliseconds, wait 5 seconds
QS_ALLINPUT); //[in]dwWakeMask
switch (dwWait)
{
case WAIT_OBJECT_0://thread exited
break;
case WAIT_OBJECT_0 + 1:
{
MSG msg;
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message != WM_QUIT)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
break;
}
}
}break;
case WAIT_TIMEOUT:
{
TRACE(_T("WARNING: Possible Deadlock detected! ThreadID: %d File: %s Line: %d\n"), GetCurrentThreadId(), _T(__FILE__), __LINE__);
}break;
}//switch(dwWait)
} while (dwWait != WAIT_OBJECT_0);
本文介绍了一个基于Windows的消息循环实现方式,其中包括使用MsgWaitForMultipleObjects进行线程等待的具体逻辑。通过不同的等待结果,文章展示了如何处理线程退出、消息处理及超时警告的情况。
743

被折叠的 条评论
为什么被折叠?



