Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Multithread - hangs on SwapBuffer

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2003
    Posts
    17

    Multithread - hangs on SwapBuffer

    Hi,

    I'm trying for several days to find an error in my application, but I'm not able to solve it, maybe you can help me.

    For the theory:

    My application is built on two different threads.
    The first thread does all rendering actions and control for the gameplay.
    The second thread is loading objects and textures that could be soon needed for gameplay.

    Through the second thread is not able to call openGL methods (needed i.e. to create textures) there is a "openGL-method-spool". If the second thread wants to call an OpenGL method, it adds a request on the spool and waits for it to be done. Thread one will then (after each frame) look if there are any requests in the spool. If so, it handles them and continues.

    So for example:
    Code :
    THREAD 1                     THREAD 2
    ========================================================
    Handle window messages       - Nothing to do -
    Render frame                 Request to load an object
    SwapBuffers                  Load files from harddrive
    Handle Spool                 Load files from harddrive
     
    Handle window messages       Add 'VBO-creation' to spool
    Render frame                 - Wait for thread 1 -
    SwapBuffers                  - Wait for thread 1 -
    Handle Spool                 - Wait for thread 1 -
     
    Handle window messages       Continue working

    and so on...


    So far for the concept of my application.

    But now one problem has come, since I activated the second thread. At critical sections (where the second thread loads a whole map) the first thread HANGS UP in the SwapBuffer method.

    Through I give out many debug informations I could figure out, that Thread 1 always hangs up in SwapBuffer while the second thread randomly hangs up somewhere (in a spoon-waiting-request, because the handle-method in Thread 1 isn't called anymore).


    I can't figure out what the reason could be - Do you maybe have any ideas?

  2. #2
    Advanced Member Frequent Contributor yooyo's Avatar
    Join Date
    Apr 2003
    Location
    Belgrade, Serbia
    Posts
    883

    Re: Multithread - hangs on SwapBuffer

    In theory it should work... Did you test your application with simple requests? Some hints...
    Code :
    void AddRequst(Requ* r)
    {
     EnterCriticalSection(&sect);
     requests.push_back(r);
     LeaveCriticalSection(&sect);
    }
     
    void ProcessRequests() // called from gl thread
    {
     EnterCriticalSection(&sect);
     for (int i=0; i<requests.size(); i++)
     {
      request[i]->Execute();
     }
     LeaveCriticalSection(&amp;sect);
     SetEvent(&amp;evDone);
    }
     
    // from data loading thread
    AddRequest(r1);
    AddRequest(r2);
    WaitForSingleObject(evDone, INFINITE);

    Keep in mind to avoid requests from function stack...
    Code :
    Req r1; AddRequest(&amp;r1); // BAD
    Req* r1 = new Req; AddRequest(r2); // GOOD

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •