<html><head><style type='text/css'>p { margin: 0; }</style></head><body><div style='font-family: arial,helvetica,sans-serif; font-size: 12pt; color: #000000'><div><font face="arial, helvetica, sans-serif"></font></div><div><font face="arial, helvetica, sans-serif">No, I don't think that llvmpipe or any other driver would have IPC data to cleanup -- even with shared surfaces these things tend to be handled transparently in kernel space.</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">But, from the documentation, it sounds like we should do no cleanup whatsoever, i.e, we should skip both </font><span style="font-family: arial, helvetica, sans-serif; font-size: 16px; ">stw_cleanup_thread() and </span><span style="font-family: arial, helvetica, sans-serif; font-size: 16px; ">stw_cleanup().</span></div><div><span style="font-family: arial, helvetica, sans-serif; font-size: 16px; "><br></span></div><div><span style="font-family: arial, helvetica, sans-serif; font-size: 16px; ">I'll update your change to do this and push.</span></div><div><span style="font-family: arial, helvetica, sans-serif; font-size: 16px; "><br></span></div><div><span style="font-family: arial, helvetica, sans-serif; font-size: 16px; ">Jose</span></div><div><font face="arial, helvetica, sans-serif"><br></font><br><hr id="zwchr" style="color: rgb(0, 0, 0); font-family: arial, helvetica, sans-serif; font-size: 12pt; "><blockquote style="color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-size: 12pt; border-left-width: 2px; border-left-style: solid; border-left-color: rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; font-weight: normal; font-style: normal; text-decoration: none; "><title></title><div style="font-family: arial,helvetica,sans-serif; color: #000000;">
<p style="margin: 0px;">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.</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">Precondition:</p>
<p style="margin: 0px;">Activate multithreading using condition variables in</p>
<p style="margin: 0px;">os_thread.h</p>
<p style="margin: 0px;">by replacing</p>
<p style="margin: 0px;"><span>#if 0 && defined (_WIN32_WINNT) && (_WIN32_WINNT >= 0x0600)</span></p>
<p style="margin: 0px;"><span>by</span></p>
<p style="margin: 0px;">#if 1 && defined (_WIN32_WINNT) && (_WIN32_WINNT >= 0x0600)</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">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.</p>
<p style="margin: 0px;">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.</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">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:</p>
<p style="margin: 0px;">At process exit </p>
<p style="margin: 0px;">DLL_PROCESS_DETACH</p>
<p style="margin: 0px;">is signaled at the method DllMain() in libgl_gdi.c, where then a final cleanup is triggered by calling </p>
<p style="margin: 0px;">stw_cleanup_thread();</p>
<p style="margin: 0px;">stw_cleanup();</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">In <span>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.</span></p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;"><span>Here some info what Microsoft proposes in such a situation:</span></p>
<p style="margin: 0px;"><span>"<span>When handling </span><strong>DLL_PROCESS_DETACH</strong><span>, a DLL should free resources such as heap memory only if the DLL is being unloaded dynamically (the </span><em>lpReserved</em><span> parameter is </span><strong>NULL</strong><span>). If the process is terminating (the </span><em>lpvReserved</em><span> parameter is non-</span><strong>NULL</strong><span>), all threads in the process except the current thread either have exited already or have been explicitly terminated by a call to the </span><a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms682658(v=vs.85).aspx" target="_blank"><strong>ExitProcess</strong></a><span> 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.</span>"</span></p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">Following this proposal i modfied the <span>DLL_PROCESS_DETACH handling in </span>DllMain:</p>
<p style="margin: 0px;"> case DLL_PROCESS_DETACH: </p>
<p style="margin: 0px;"> stw_cleanup_thread(); </p>
<p style="margin: 0px;"> if (NULL==lpReserved) </p>
<p style="margin: 0px;"> { </p>
<p style="margin: 0px;"> stw_cleanup(); </p>
<p style="margin: 0px;"> } </p>
<p style="margin: 0px;"> break;</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">This change indeed solved this issue for me and LLVMPIPE runs fine.</p>
<p style="margin: 0px;">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. </p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">Any comments on this issue?</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;"> </p>
</div><br>_______________________________________________<br>mesa-dev mailing list<br>mesa-dev@lists.freedesktop.org<br>http://lists.freedesktop.org/mailman/listinfo/mesa-dev<br></blockquote><br></div></div></body></html>