Hi Robert

I discovered an issue with multithreading. Consider the following Code in 
ViewerBase::startThreading:


Code:

void ViewerBase::startThreading()
{
    .... 

    if (_threadingModel==CullThreadPerCameraDrawThreadPerContext && 
numThreadsOnStartBarrier>1)
    {
        Cameras::iterator camItr;

        ....

        for(camItr = cameras.begin();
            camItr != cameras.end();
            ++camItr)
        {
            osg::Camera* camera = *camItr;
            if (camera->getCameraThread() && 
!camera->getCameraThread()->isRunning())
            {
                OSG_INFO<<"  camera->getCameraThread()-> 
"<<camera->getCameraThread()<<std::endl;
               [b] camera->getCameraThread()->startThread();[/b]
            }
        }
    }

    ....

    for(citr = contexts.begin();
        citr != contexts.end();
        ++citr)
    {
        osg::GraphicsContext* gc = (*citr);
        if (gc->getGraphicsThread() && !gc->getGraphicsThread()->isRunning())
        {
            OSG_INFO<<"  gc->getGraphicsThread()->startThread() 
"<<gc->getGraphicsThread()<<std::endl;
            [b]gc->getGraphicsThread()->startThread();[/b]
            // OpenThreads::Thread::YieldCurrentThread();
        }
    }

    _threadsRunning = true;

    OSG_INFO<<"Set up threading"<<std::endl;
}





We suppose that each call to startThread actually starts the tread. When the 
call returns the thread is actually running.
BUT: there are cases where for some reason the thread was not able to start. We 
had such a issue where our 32-bit process was running on 3GB memory limit and 
the thread was refused !! There might be other cases , errno is your friend in 
telling you what was the reason (so was for me).

Actually Thread::startThread returns an int which is non-zero for such cases. 
You should update the startThreading method to react accordingly when such an 
error case occures. Otherwise OSG assumes that threads are running, but nothing 
is happening and some thread sync wait calls end up dead-locked!


Regards
Daniel

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





_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to