Created
October 27, 2011 08:07
-
-
Save binshengliu/1319029 to your computer and use it in GitHub Desktop.
notify the working thread to quit safely
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// main thread | |
m_KillThreadEvent.SetEvent(); | |
while (TRUE) { | |
DWORD result; | |
MSG msg; | |
result = ::MsgWaitForMultipleObjects(1, &m_hPositioning, FALSE, INFINITE, QS_ALLINPUT); | |
if (result == (WAIT_OBJECT_0)) { | |
break; | |
} else if (result == ((DWORD)0xFFFFFFFF)) { | |
DWORD e = GetLastError(); | |
} else { | |
::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE); | |
::TranslateMessage(&msg); | |
::DispatchMessage(&msg); | |
} | |
} | |
CloseHandle(m_hPositioning); | |
// working thread | |
while (WaitForSingleObject(pParam->pKillThreadEvent->m_hObject, 0) == WAIT_TIMEOUT) { | |
// do something | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment