Hi Robert,

Unfortunately serializing the access to getenv() is not likely to solve
the issue. The problem is not that OSG calls several getenv() in
parallel, the problem is that getenv() should not be called *at all* in
DllMain().

Serializing getenv() in OSG does not guarantee that another C function
will not be called in another thread unrelated to OSG. In fact, this is
exactly what is happening to us.

Wrt to Daniel's suggestion, it's a variant of the double checked
locking, which is unfortunately subtly broken (cf. previous post).


Regards,

Tanguy


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Robert
Osfield
Sent: 06 August 2009 12:48
To: OpenSceneGraph Users
Subject: Re: [osg-users] Deadlock when loading osg.dll, singletons are
evil

Hi Tanguy,

I was wondering about the possibility of wrapping up the access to the
sensitive C functions using a Mutex.  We couldn't do it in local code,
but would need to do it via a single custom getenv() etc. function
implementation, otherwise we'd still end up with multiple functions
potentially accessing standard C functions like getenv in a parallel.

Like Daniel's suggestion of moving the Mutex into the getenv init
avoiding the overuse of the locking the mutex, doing the lock in
central function would also achieve this aim.

So perhaps we co do something like:

static Mutex s_mutex;

const char* serialized_getenv(const char* str)
{
    ScopedLock lock(s_mutex);
    return getenv(str);
}

void* serialized_otherSensitiveCFunction(...)
{
   ScopedLock lock(s_mutex);
   return otherSensitiveCFunction(...);
 }

Then all the init code would call these methods.  Note the
implementations would all be in the .cpp's.

Thoughts?
Robert.
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.or
g
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to