线程安全退出

来源:百度文库 编辑:神马文学网 时间:2024/04/26 21:07:58
    if(m_pThread)
    {
        DWORD dwCode = 0;
        BOOL bRst = GetExitCodeThread(m_pThread-> m_hThread,   &dwCode);
        if(!bRst ||  dwCode   !=  STILL_ACTIVE)
        {
            return;
        }

        m_bAbort = true;
        SetThreadPriority(m_pThread->m_hThread, THREAD_PRIORITY_HIGHEST);
        Sleep(1);
        if(WAIT_OBJECT_0 != WaitForSingleObject(m_pThread->m_hThread,500))
        {
            TerminateThread(m_pThread->m_hThread, 0);
        }
        m_pThread = NULL;
    }