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
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to