Skip to content

Instantly share code, notes, and snippets.

@binshengliu
Created October 27, 2011 08:07
Show Gist options
  • Save binshengliu/1319029 to your computer and use it in GitHub Desktop.
Save binshengliu/1319029 to your computer and use it in GitHub Desktop.
notify the working thread to quit safely
// 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