C++/VB - Deadly embrace between SetUnhandledExceptionFilter() and thread rundown(???) in Server 2003
Asked By j_314
05-Jan-10 12:34 AM

When our application starts up we call SetUnhandledExceptionFIlter()
and save off the address it returns as the current exception handler.
When we are exiting we pass this saved value back into
SetUnhandledExceptionFIlter() to re-establish the exception handler
that existed before we started. We also start a couple of threads.
Very occasionally we find that we do not shut down cleanly and if we
take a look with the debugger we find two thread in the process with
the following call stacks. It appears there is some kind of deadly
embrace in the use of critical sections between the code in
SetUnhandledExceptionFilter() and whatever code the other thread is
running (probably as part of thread cleanup but we are not sure).
This is Windows Server 2003 R2 SP2 (Enterprise Edition).
Does anyone know whether this is a known problem? Something which has
been fixed perhaps in Server 2008?
Thread #1:
0 > 3520 Main Thread Main Thread _unlock Normal 0
0 3200 Worker Thread Win32 Thread 7c82860c Normal 0
ntdll.dll!_ZwWaitForSingleObject@12() + 0xc bytes
ntdll.dll!_RtlpWaitOnCriticalSection@8() - 0xe4 bytes
ntdll.dll!_RtlEnterCriticalSection@4() + 0x22f51 bytes
ntdll.dll!_LdrLockLoaderLock@12() + 0x6b bytes
kernel32.dll!_GetModuleFileNameW@12() + 0x51 bytes
kernel32.dll!_FillUEFInfo@8() + 0x4d bytes
digger.exe!__tmainCRTStartup() Line 586 + 0x17 bytes C
kernel32.dll!_BaseProcessStart@4() + 0x23 bytes
Thread #2:
0 3520 Main Thread Main Thread _unlock Normal 0
0 > 3200 Worker Thread Win32 Thread 7c82860c Normal 0
ntdll.dll!_KiFastSystemCallRet@0()
ntdll.dll!_ZwWaitForSingleObject@12() + 0xc bytes
ntdll.dll!_RtlpWaitOnCriticalSection@8() - 0xe4 bytes
ntdll.dll!_RtlEnterCriticalSection@4() + 0x22f51 bytes
ntdll.dll!__LdrpInitialize@12() + 0x56 bytes
ntdll.dll!_KiUserApcDispatcher@16() + 0x25 bytes
Windows Server 2003 R2
(1)
GetModuleFileNameW
(1)
FillUEFInfo
(1)
KiUserApcDispatcher
(1)
LdrLockLoaderLock
(1)
TmainCRTStartup
(1)
LdrpLoaderLock
(1)
DLLs
(1)
Jochen Kalmbach [MVP] replied to j_314
Hi j_3140!
IMHO there is no need to restore the original handler...
--
Greetings
Jochen
My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Joey replied to Jochen Kalmbach [MVP]
Thank you for the suggestion.
We included this code because we may be loaded as a DLL by some
other software package which may have a handler of its own and we are
trying to be a good citizen and leave the process state the same as
we
found it.
I suppose we could just remove this call to SetUnhandledExceptionFilter
()
but that still leaves a question as to whether there is some bug
here in the kernel which needs to be fixed. In general this kind of
deadly embrace is because someone has messed up the order of
acquisition of resources so the two threads are blocking each other.
Pavel Lebedinsky [MSFT] replied to j_314
To me it looks like both of these threads are blocked on the loader
lock. Can you check which thread owns it? In windbg/cdb you can
use the following command to do this:
0:000> !cs ntdll!LdrpLoaderLock
--
Pavel Lebedinsky/Windows Fundamentals Test
This posting is provided "AS IS" with no warranties, and confers no rights.
m replied to j_314
In my experience, several of the Windows DLLs do not shutdown cleanly
(specifically DNS APIs and others) and a call to ExitProcess from the main
thread is necessary. This is usually performed by the CRT when Main
returns, but may not be for some special applications. IMHO, the shutdown
logic is less well tested and debugged in Windows than the other APIs.
Jonathan de Boyne Pollard replied to j_314
http-equiv="Content-Type">
cite="mid:2340b5b1-382a-4285-9a8a-91d0724eeb1b@f5g2000yqh.googlegroups.com"
type="cite">
and save off the address it returns as the current exception handler.
When we are exiting we pass this saved value back into <code>SetUnhandledExceptionFilter()</code>
to re-establish the exception handler that existed before we started.
We also start a couple of threads.<br>
href="http://blogs.msdn.com/oldnewthing/archive/2007/05/03/2383346.aspx">this</a>,
href="http://blogs.msdn.com/oldnewthing/archive/2009/02/06/9400367.aspx">this</a>,
and <a
href="http://blogs.msdn.com/oldnewthing/archive/2008/05/06/8461730.aspx">this</a>.
Don't assume that you can cleanly use multiple threads after the main
thread (or, indeed, any thread) has commenced process exit.<br>
Jonathan de Boyne Pollard replied to m
http-equiv="Content-Type">
cleanly (specifically DNS APIs and others) and a call to ExitProcess
from the main thread is necessary. </p>
Jonathan de Boyne Pollard replied to m
http-equiv="Content-Type">
type="cite">
style="border-left: 2px solid rgb(0, 0, 0); padding-left: 5px; padding-right: 0px; margin-left: 5px; margin-right: 0px;">
type="cite">
cleanly (specifically DNS APIs and others) and a call to <code>ExitProcess</code>
from the main thread is necessary. </p>
Jonathan de Boyne Pollard replied to m
C++ / VB Hello, I have a text file called OS.txt that looks like this: Windows 2000 Professional 5.0 (2195) Windows 2000 Server 5.0 (2195) Windows 7 Professional 6.1 (7600) Windows 7 Professional 6.1 (7600) Windows 7 Professional 6.1 (7600) Windows 7 Professional 6.1 (7600 Windows 7 Ultimate 6.1 (7100) Windows NT 4.0 Windows NT 4.0 Windows Server
are VBscript on Windows server 2003 and VBscript on WS2008 compatible? C++ / VB Hi everybody, Sorry if my question has already clear for me on this point. I spent a lot of time learning VBscript on Windows server 2003 (my sources are script56.chm and script_center.chm files), especially VBscript for using Active Directory am rather satisfied. I would like to know if my scripts will always work on Windows server 2008 or if, after migration to Windows 2008, I would have to rewrite my scripts
it was design purely for WIN32 and never had to worry about the version of windows users had. That seem to change now. So I guess, the deeper questions and answers A new GUI foundation? Do you recommend WPF over MFC? - - HLS VC MFC Discussions SQL Server (1) Visual Studio (1) Silverlight (1) Windows 7 (1) Office (1) Linux (1) Adobe (1) Perl (1) I am using the RC in VS2010. VS2010 has the VC6-style ClassWizard, a welcome-back addition. It also has Windows 7-oriented enhancements to MFC. And an MFC ribbon designer (for the ribbon that debuted machine to run it. Build times are pretty quick. MFC is a GUI framework, requiring Windows. WPF is a GUI framework requiring .NET. WinForms is another GUI framework requiring .NET. WPF addition, WPF is a superset of Silverlight, which is how you program the recently announced Windows Phone (which replaces Windows Mobile). So for career longevity, learning WPF / Silverlight is inevitable. Now that Windows 7 ships with .NET Framework 3.5 SP1, the preinstalled base of .NET is growing
Slow text IO on 32 bit Windows 7 C++ / VB We have a customer reporting that our product draws text slowly on Windows 7. Upon further investigation, it appears as if 32 bit Windows 7 itself draws text slowly. I wrote a test program that uses printf to write 5000 times and it seems to run 2 to 9 times slower on 32 bit Windows 7 than on 64 bit Windows XP. (I am testing those systems using Vmware running on 64 bit Windows XP.) The performance on native 64 bit Windows 7 seems fine. Our product uses the standard wide character versions of WIN32 SDK APIs very fast on XP. Can anyone suggest why it is so slow on 32 bit Windows 7? Is there a known problem with text output on that system? Thank you. David
bottleneck is memory bandwidth rather than CPU cycles. Is this analysis correct? VC MFC Discussions Windows XP (1) PowerPoint (1) Windows 7 (1) Vista (1) XP (1) CMemoryMapFile (1) MapViewOfFile (1) GlobalMemoryStatus (1) Geez, and here work via google groups and I have not see it yet here in microsoft's server. Lets wait 10 minutes or so before i post it again here. . . FT! Here it wrote for him. I have a version where I am exploring NUMA that will leverage 2003+ Windows technology. I am going to pencil in getting a test computer with a Intel XEON at least understand this his old memory usage paradigm for processes does not apply under Windows. The only reason I can suspect for his ignorance is that he is not a programmer or at the very least, very primitive nature of programming knowledge. A real Windows programmer would under this this basic principles or at least explore what experts are saying reason is that you are not using pure RAM for the entire load of data. Windows will virtualize everything. In basic terms, there are two kinds - Windows using memory maps internally