Hi Colin,

I'm not in favour of adding a mutex just to protect a possible static
initialization issue as this would add an overhead to all calls to
isTextureMode(..) when it's just multi-threaded initialization that is
problematic.   Perhaps a global static initializer object could call
te isTextureMode to make sure it's initialized.

ie.  add something like the following to Texture.cpp:

struct MyInitializer
{
   MyInitializer()
   {
      osg::getTextureGLModeSet(); // force initialization
   }
}

static MyInitializer s_myInitializer;

Could you try this and let me know if this works fine?

Robert.


On Wed, Aug 31, 2011 at 4:01 PM, Colin Branch <[email protected]> wrote:
> I'm using VC9 64-bit. The application creates multiple threads and loads and
> saves files (think of it like a parallel osgConv).
>
> It is crashing here.
> static TextureGLModeSet& getTextureGLModeSet()
> {
>     static TextureGLModeSet s_textureGLModeSet;
>     return s_textureGLModeSet;
> }
>
> This is called by bool osg::isTextureMode(StateAttribute::GLMode mode)
> during loading files. This static object creation is not threadsafe and thus
> is crashes when two threads attempt to create the set at the same time. I
> noticed problems with this function were reported before
> http://comments.gmane.org/gmane.comp.graphics.openscenegraph.user/2732
>
> One potential solution would be copying the mutex based implementation
> located at static const Node::DescriptionList& getStaticDescriptionList()
>
> The solution I currently have explicitly calls osg::isTextureMode(0); before
> starting the threads. Which works however it is not a good solution for
> applications who have not run into this problem.
>
> Regards,
> Colin Branch
> --
> Colin Branch
> Senior Software Engineer, VR-Vantage
> VT-MAK
>
>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to