[Mesa-dev] llvmpipe process shutdown bug on windows

Rob Schneider Swizzle at t-online.de
Fri Jan 4 12:22:18 PST 2013


When using LLVMPIPE on Windows 7 OS, i noticed that it is very simple
to run into a situation where the process hangs at application exit. 

	Precondition: 

	Activate multithreading using condition variables in 

	os_thread.h 

	by replacing 

	#if 0 && defined (_WIN32_WINNT) && (_WIN32_WINNT >= 0x0600) 

	by 

	#if 1 && defined (_WIN32_WINNT) && (_WIN32_WINNT >= 0x0600) 

	I remember this issue came up recently where it was explained that
this is currently not activated by default since Windows XP does not
support those condition variables. 

	However, the performance is much faster when using those condition
variables, so if XP support is not required one definitely wants to
run in this mode. 

	When this mode is activated, i noticed that an application using
LLVMPIPE based OpenGL will typically hang at process exit. Attaching a
debugger shows what the root cause is: 

	At process exit  

	DLL_PROCESS_DETACH 

	is signaled at the method DllMain() in libgl_gdi.c, where then a
final cleanup is triggered by calling  

	stw_cleanup_thread(); 

	stw_cleanup(); 

	In stw_cleanup() code is triggered that tries to communicate a
shutdown to the spawned threads - however at that time those threads
have already been terminated by the OS and so the process hangs. 

	Here some info what Microsoft proposes in such a situation: 

	"When handling DLL_PROCESS_DETACH, a DLL should free resources such
as heap memory only if the DLL is being unloaded dynamically (the
lpReserved parameter is NULL). If the process is terminating (the
lpvReserved parameter is non-NULL), all threads in the process except
the current thread either have exited already or have been explicitly
terminated by a call to the ExitProcess [1] function, which might
leave some process resources such as heaps in an inconsistent state.
In this case, it is not safe for the DLL to clean up the resources.
Instead, the DLL should allow the operating system to reclaim the
memory." 

	Following this proposal i modfied the DLL_PROCESS_DETACH handling in
DllMain: 

	    case DLL_PROCESS_DETACH:      

	    stw_cleanup_thread();      

	    if (NULL==lpReserved)      

	    {        

	        stw_cleanup();      

	    }      

	    break; 

	This change indeed solved this issue for me and LLVMPIPE runs fine. 

	The question that comes up for me is if LLVMPIPE has any inter
process code that would need cleanup in such a situation - otherwise
one might think of using this change to resolve this issue on Windows.
 

	Any comments on this issue?

Links:
------
[1]
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682658(v=vs.85).aspx
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20130104/6a694a84/attachment.html>


More information about the mesa-dev mailing list