mercredi 28 juin 2017

std::Thread Join stuck C++

I've a problem with the std::thread join function. When i try to call for my my thread to finish, it execute until the end of my function but get stuck after that.

int C_anccap::LoopAnimation()
{


    MSG        msg;
        wglMakeCurrent(m_hDC, m_hRC);
        // Animation loop.
        //Loop until i change static variable to true
        while (!C_anccap::exit) {

    //
    //  Process all pending messages 
    // 
    while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) == TRUE) {
        if (GetMessage(&msg, NULL, 0, 0)) {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        else {
            return TRUE;
        }
    }
    if (anccap.CaptureVideo() != GL_FAILURE_NV)
    {
        anccap.DisplayVideo();
        rec[0].RecordShot(m_SDIin.GetTextureObjectHandle(0));
    }
}
anccap.Shutdown();
wglMakeCurrent(m_hDC, NULL);

}

//This is how i launch my thread 
    capturethread = std::thread(&C_anccap::LoopAnimation, this);

//Here is how i'm trying to join, i've try with and without mutex
case WM_CLOSE: 
        {
            std::mutex mtx;
            mtx.lock();
            C_anccap::exit = true;
                mtx.unlock();
//get stuck here
                anccap.capturethread.join();
                PostQuitMessage (0);
                DestroyWindow (hWnd); 
                break; 
            }

I've already check, i launch and call join in the main thread. Is it something like a deadlock and i'm missing something? If you have any ideas Thanks

Aucun commentaire:

Enregistrer un commentaire