Asynchrone Threads?

  • Asynchrone Threads?

    Hallo Easy-Coding Community,

    Problem:
    Ich habe eine Rendering Funktion, die in einer while(true) läuft. Darin ist ein Aufruf zum Matchen des Bildes, welcher das Bild alle 10 Frames ansuchen soll. Das funktioniert auch sehr gut. Nur stoppt das Bild dafür etwa 1 Sekunde. Da dachte ich mit, klar mache ich das Teil in einen Thread. Nur wartet die Render Funktion weiterhin auf die Match Funktion bis sie fertig ist. Habt ihr eine Idee wie ich das machen kann, dass der Matcher asynchron zum Rendern läuft.

    Kurz gesagt, wenn er das Bild analysiert hat soll er sich einfach Melden und das Ergebnis einblenden.

    Danke und Grüße,
    Sw00sh!

    Quellcode

    1. HRESULT
    2. MRBBApp::Render(){
    3. HRESULT hr = S_OK;
    4. try{
    5. // Get Video
    6. m_pCamera->GetVideoBuffer(m_pData);
    7. if(this->frameCounter != 0 && this->frameCounter % 10 == 0){
    8. matcher->match(m_iVideoImgWidth, m_iVideoImgHeight,sizeof(short),(short*)m_pData,TEMP);
    9. //<--- Die Funktion soll asynchron zum Rest laufen
    10. }
    11. // Set Video Texture
    12. //m_pData is RGB565
    13. m_pBackPlane->SetTexture(m_pData);
    14. // Clear the backbuffer to a blue color
    15. hr = m_pD3DMDevice->Clear( 0, NULL, D3DMCLEAR_TARGET | D3DMCLEAR_ZBUFFER, D3DMCOLOR_XRGB(0,0,255), 1.0f, 0 );
    16. // Begin the scene
    17. if( SUCCEEDED( hr = m_pD3DMDevice->BeginScene() ) ){
    18. // Draw Video Background
    19. m_pBackPlane->Draw();
    20. hr = m_pD3DMDevice->EndScene();
    21. }
    22. hr = m_pD3DMDevice->Present( NULL, NULL, NULL, NULL );
    23. }catch(...){
    24. OutputDebugString(L"Exception in Render-Loop caught!\n");
    25. MessageBox(NULL,L"Exception in Render-Loop!", L"Error!", MB_OK | MB_ICONERROR);
    26. return E_FAIL;
    27. }
    28. CalculateFramerate();
    29. return hr;
    30. }
    Alles anzeigen
  • Servus,

    für den Fall das es jemand interessiert.

    Im Konstuktor

    Quellcode

    1. this->hThread = CreateThread(NULL, 0, MMRTTemplateMatching::run , this, 0, &this->dwThreadId);


    Im Destruktor

    Quellcode

    1. CloseHandle(hThread);


    Quellcode

    1. static DWORD WINAPI run(LPVOID mmrtt){
    2. ((MMRTTemplateMatching*)mmrtt)->match();
    3. }

    Match läuft jetzt schön parallel :)