当在使用参数DLL_THREAD_DETACH的DLLMain入口点调用的函数中发生本地静态变量的初始化时,我的应用程序中发生死锁。
以下是Windbg分析
这通常是由另一个持有加载程序锁的线程引起的。
以下是Locks Held。
CritSec ntdll!LdrpLoaderLock + 0 at 7c97e178
LockCount 3
RecursionCount 1
OwningThread 17e8
EntryCount d
ContentionCount d
***已锁定
CritSec MSVCR80!__ app_type + 94 at 781c3bc8
LockCount 1
RecursionCount 1
OwningThread 1100
EntryCount 1
ContentionCount 1 ***锁定
#调用堆栈线程17e8
781c3bc8 78132bd9 0777fde4 ntdll!RtlEnterCriticalSection + 0x46
00000008 b87d2630 00000000 MSVCR80!_lock + 0x2e
0864ae10 08631d7f 0864ae10 EPComUtilities32!_onexit + 0x36
0864ae10 b87d2588 00000001 EPComUtilities32!atexit + 0x9
0777fea8 0864719f 08630000 EPComUtilities32!XCriticalSectionEx :: ThreadTerminated + 0x5f
08630000 00000003 00000000 EPComUtilities32!DllMain + 0x20
08630000 7c90118a 08630000 EPComUtilities32!__ DllMainCRTStartup + 0x7a
08630000 00000003 00000000 EPComUtilities32!_DllMainCRTStartup + 0x1d
#调用堆栈线程1100
000000b0 00000000 00000000 ntdll!ZwWaitForSingleObject + 0xc
000000b0 ffffffff 00000000 kernel32!WaitForSingleObjectEx + 0xa8
000000b0 ffffffff 06ce64e0 kernel32!WaitForSingleObject + 0x12
000480ba 000f4240 00000000 CATSysMultiThreading!CATThreads :: Join + 0xf5
0012fcc8 00000004 00000000 JS0GROUP!CATLM :: StopHB + 0xf4
d138509f 00416694 00000001 JS0GROUP!CATLM :: Unmake + 0x6b
00000000 00000000 00000000 MSVCR80!_cinit + 0xd6
00000000 0012fd6c 081e68d9 MSVCR80!退出+ 0xd
00000000 06d404f0 0998fb90 JS0GROUP!CATExit + 0x1d
<00> 00000000 004ef366 0000000d DNBPLMProvider!DNBEPLMTransactionMgt :: OnApplicationExit + 0x229 <00> 00000000 0012fd9c 004eabfc JS0GROUP!CATCallExits + 0x2bc <00> 00000000 0012ff7c 0040cefd JS0GROUP!CATErrorNormalEnd + 0x31 00000000 06ce71d0 06ce71d0 JS0GROUP!CATExit + 0xc00000007 06cdb120 059b61d8 DLMMfgContextSolver!main + 0x146d
ffffffff ffffffff bffde000 DLMMfgContextSolver!__ tmainCRTStartup + 0x10f
#请给出意见,了解可能导致死锁的原因。 注意:当我将静态变量设置为非静态时,问题会在论坛Deadlock occurs in Function Scoped Static variables (Thread Unsafe in VC++)
中发布的示例的上下文中消失