We've tried to temporarily fix the problem on our side by commenting out
osg::DisplaySettings::readEnvironmentalVariables() implementation.

But the deadlock was not gone, now it locks on the following line:

Glextensions.cpp, line 42 (oh, the irony)
static const char* envVar = getenv("OSG_GL_EXTENSION_DISABLE");

I don't think it can get any simpler than that.


Aymeric, are we still trying to make a small example program? I was
thinking that you could spawn several processes of an unsafe program
(that would show this problem) in a loop until one of them deadlocks.


Tanguy


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Aymeric
Barthe
Sent: 30 July 2009 07:46
To: [email protected]
Subject: Re: [osg-users] Deadlock when loading osg.dll, singletons are
evil


bthrall wrote:
> 
> The links you posted explicitly said that creating synchronization
primitives is allowed in DllMain; the problem is acquiring them when
other threads are trying to acquire the loader lock (to enter some
DllMain function). Are you saying that the problem is the mutex used in
creating the singletons, or is there some other limitation of DllMain
that you think OSG is violating?
> 


The violation is that no C function should be called from DllMain(). 

The problem is that not only the loader lock is taken (because in
DllMain), but since you use a standard C function, another lock might be
taken by the CRT. In this specific case, getenv() is called and the
Microsoft CRT takes the CRT lock _ENV_LOCK (getenv.c at line 81).

In the meantime, we have another thread that uses CURL, and is trying to
use the C function stat(). It so happens that stat() will take the CRT
locks _TIME_LOCK (tzset.c at line 90) and _ENV_LOCK (tzset.c at line
135). Then GetTimeZoneInformation() is called and decides it needs to
load ntdll to do the job and thus attempts to get the loader lock...
boom!

Classical deadlock. 
1-> Thread-A: loaderlock taken by LoadLibrary() of OSG
2-> Thread-B: use stat()
3-> Thread-B: stat() takes _ENV_LOCK
4-> Thread-B: LoadLibrary() fails to take loaderlock (see 1)
5-> Thread-A: DllMain of Osg calls getenv() which fails to get _ENV_LOCK
(see 3)

Aymeric Barthe

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





_______________________________________________
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