Hi,

I am porting a small project that is still in starting stages from using 
irrlicht to osg (because osg seems more professional)
However I encountered a problem:

I'm using some custom multithreading (windows thread + mutex + event), to start 
a second thread that handles the generation and/or loading of chunks, so that 
the main thread can keep running at normal speed. I have CPU cores in my PC.

Now it used to work fine, the chunks would generate/load without slowing down 
the rendering etc. of the main thread, but currently when using OSG the main 
thread slows down when the second thread is generating/loading chunks. 

So it seems that it does not run it in a seperate thread at all, or that it 
runs it at the same core or something. Any idea why this is, or what I could do 
to check things, or fix it?


Code:
chunkRequest_mutex = CreateMutex( NULL,    // no security attributes
                                                        false,   // BOOL 
bInitialOwner, we don't want the
                                                                                
// thread that creates the mutex to
                                                                                
// immediately own it.
                                                        "ChunkRequestMutex" // 
lpName
                                                        );
        if ( chunkRequest_mutex == NULL )
        {
                OutputDebugString("CreateMutex() failed for request\n" );
        }
        else OutputDebugString("CreateMutex() success for request\n" );

        chunkRequest_event = CreateEvent( NULL,     // no security attributes
                                                FALSE,    // auto-reset event
                                                FALSE,    // initial state is 
non-signaled
                                                "ChunkRequestEvent" );    // 
lpName

        if (chunkRequest_event == NULL) 
        {
                OutputDebugString("CreateEvent() failed for request\n");
        }
        else OutputDebugString("CreateEvent() success for request\n" );


        chunkCreated_mutex = CreateMutex( NULL,    // no security attributes
                                                        false,   // BOOL 
bInitialOwner, we don't want the
                                                                                
// thread that creates the mutex to
                                                                                
// immediately own it.
                                                        "ChunkCreatedMutex" // 
lpName
                                                        );
        if ( chunkRequest_mutex == NULL )
        {
                OutputDebugString("CreateMutex() 2 failed for request\n" );
        }
        else OutputDebugString("CreateMutex() 2 success for request\n" );


        //create and start thread
        HANDLE   chunkHandle;
    unsigned  chunkThreadID;


        DWORD   dwExitCode;
        
        chunkHandle = (HANDLE)_beginthreadex( NULL,
                                          0,
                                          handleChunkRequests,
                                          NULL,
                                          CREATE_SUSPENDED, // so we can later 
call ResumeThread()
                                          &chunkThreadID );

    if ( chunkHandle == 0 )
        printf("Failed to create consumer thread\n");

    GetExitCodeThread( chunkHandle, &dwExitCode );  // should be STILL_ACTIVE = 
0x00000103 = 259
    printf( "initial Consumer thread exit code = %u\n", dwExitCode );


    ResumeThread( chunkHandle );   //



Thank you!

Cheers,
Bram

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=52842#52842





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to