Print Page | Close Window

Deadlock?

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Skin Framework
Forum Description: Topics Related to Codejock Skin Framework
URL: http://forum.codejock.com/forum_posts.asp?TID=24629
Printed Date: 27 February 2026 at 8:52pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Deadlock?
Posted By: rdhd
Subject: Deadlock?
Date Posted: 27 February 2026 at 4:49pm
I see this once in a while. I am starting up a debug session and open one of our files. The app hangs. take a look at this code:

_XTP_EXT_CLASS CXTPSkinManager* AFX_CDECL XTPSkinManager()
{
    XTP_SKINFRAMEWORK_GLOBALLOCK_SHARED_SCOPE();

    if (CXTPSkinManager::s_pInstance == NULL)
    {
        CXTPSkinManager::s_pInstance = &XTPSkinManagerSingleton::Instance();
    }

    return CXTPSkinManager::s_pInstance;
}

Note this line:

    XTP_SKINFRAMEWORK_GLOBALLOCK_SHARED_SCOPE();

On the main thread the stack is:

     ToolkitPro2410vc170x64UD.dll!CXTPSimpleCriticalSection::Enter() Line 100    C++
     ToolkitPro2410vc170x64UD.dll!CXTPSimpleCriticalSection::CLock::CLock(CXTPSimpleCriticalSection & cs) Line 169    C++
     ToolkitPro2410vc170x64UD.dll!CXTPRWCriticalSection::LockShared(int bPopMode) Line 327    C++
     ToolkitPro2410vc170x64UD.dll!CXTPRWCriticalSection::LockShared() Line 227    C++
     ToolkitPro2410vc170x64UD.dll!CXTPRWCriticalSection::CSharedLock::CSharedLock(CXTPRWCriticalSection & cs) Line 311    C++
>    ToolkitPro2410vc170x64UD.dll!XTPSkinManager() Line 914    C++

In the Enter() function I am stuck in this loop:

            while (0 != m_nLock)
            {
                Sleep(dwTimeout);
                if (dwTimeout < XTP_SYNC_MAX_EXPONENTIAL_TIMEOUT)
                {
                    dwTimeout <<= 1;
                }
            }

Examining the plethora of ToolkitPro worker threads I find this one:

     ntdll.dll!NtWaitForAlertByThreadId()    Unknown
     ntdll.dll!RtlpWaitOnCriticalSection()    Unknown
     ntdll.dll!RtlpEnterCriticalSectionContended()    Unknown
     ntdll.dll!RtlEnterCriticalSection()    Unknown
     ucrtbased.dll!00007ff8aa103817()    Unknown
     ucrtbased.dll!00007ff8aa0ffb5a()    Unknown
     ucrtbased.dll!00007ff8aa0fffcd()    Unknown
     ucrtbased.dll!00007ff8aa0ff4df()    Unknown
>    mfc140ud.dll!operator new(unsigned __int64 nSize, int nType, const char * lpszFileName, int nLine) Line 47    C++
     mfc140ud.dll!CObject::operator new(unsigned __int64 nSize, const char * lpszFileName, int nLine) Line 67    C++
     ToolkitPro2410vc170x64UD.dll!CXTPRWCriticalSection::IncrementLocalSharedLockCounter() Line 374    C++
     ToolkitPro2410vc170x64UD.dll!CXTPRWCriticalSection::LockShared(int bPopMode) Line 337    C++
     ToolkitPro2410vc170x64UD.dll!CXTPRWCriticalSection::LockShared() Line 227    C++
     ToolkitPro2410vc170x64UD.dll!CXTPRWCriticalSection::CSharedLock::CSharedLock(CXTPRWCriticalSection & cs) Line 311    C++
     ToolkitPro2410vc170x64UD.dll!XTPSkinManager() Line 914    C++
     ToolkitPro2410vc170x64UD.dll!CXTPSkinManagerDetoursApiHook::OnHookGetProcAddress(HINSTANCE__ * hModule, const char * pszProcName) Line 2040    C++
     clr.dll!__delayLoadHelper2()    Unknown
     clr.dll!__tailMerge_ole32_dll()    Unknown
     clr.dll!RegMeta::CreateNewMD()    Unknown
     clr.dll!Disp::DefineScope()    Unknown
     clr.dll!PEFile::DefineEmitScope()    Unknown
     clr.dll!Assembly::CreateDynamic()    Unknown
     clr.dll!AppDomainNative::CreateDynamicAssembly()    Unknown
     mscorlib.ni.dll!00007ff9aef92b48()    Unknown
     mscorlib.ni.dll!00007ff9aef92957()    Unknown
     mscorlib.ni.dll!00007ff9af9a640d()    Unknown
     mscorlib.ni.dll!00007ff9af03bbec()    Unknown
     mscorlib.ni.dll!00007ff9af9a5e2e()    Unknown
     00007ff9511f8242()    Unknown
     00007ff9511f2ae1()    Unknown
     00007ff9511f2607()    Unknown
     mscorlib.ni.dll!00007ff9aeff9f93()    Unknown
     mscorlib.ni.dll!00007ff9aeff9bcd()    Unknown
     00007ff9511ec3e7()    Unknown
     00007ff9511e6fd4()    Unknown
     00007ff9511e482e()    Unknown
     00007ff9511e35a3()    Unknown
     00007ff9511e3501()    Unknown
     00007ff9511b5468()    Unknown
     clr.dll!CallDescrWorkerInternal()    Unknown
     clr.dll!CallDescrWorkerWithHandler()    Unknown
     clr.dll!CallDescrWorkerReflectionWrapper(struct CallDescrData *,class Frame *)    Unknown
     clr.dll!RuntimeMethodHandle::InvokeMethod()    Unknown
     mscorlib.ni.dll!00007ff9aeffef68()    Unknown
     mscorlib.ni.dll!00007ff9aefdaa16()    Unknown
     clr.dll!CallDescrWorkerInternal()    Unknown
     clr.dll!CallDescrWorkerWithHandler()    Unknown
     clr.dll!MethodDescCallSite::CallTargetWorker()    Unknown
     clr.dll!DispatchInfo::InvokeMemberWorker(struct DispatchMemberInfo *,struct InvokeObjects *,int,int,int,int &,int &,long,struct tagDISPPARAMS *,struct tagVARIANT *,unsigned short,unsigned long,long *,struct tagVARIANT *,struct OBJECTHANDLE__ * *,int *,struct tagVARIANT * *)    Unknown
     clr.dll!DispatchInfo::InvokeMemberDebuggerWrapper(struct DispatchMemberInfo *,struct InvokeObjects *,int,int,int,int &,int &,long,struct tagDISPPARAMS *,struct tagVARIANT *,unsigned short,unsigned long,long *,struct tagVARIANT *,struct OBJECTHANDLE__ * *,int *,struct tagVARIANT * *,class Frame *)    Unknown
     clr.dll!DispatchInfo::InvokeMember(struct SimpleComCallWrapper *,long,unsigned long,unsigned short,struct tagDISPPARAMS *,struct tagVARIANT *,struct tagEXCEPINFO *,struct IServiceProvider *,unsigned int *)    Unknown
     clr.dll!InternalDispatchImpl_Invoke(struct IDispatch *,long,struct _GUID const &,unsigned long,unsigned short,struct tagDISPPARAMS *,struct tagVARIANT *,struct tagEXCEPINFO *,unsigned int *)    Unknown
     clr.dll!Dispatch_Invoke(struct IDispatch *,long,struct _GUID const &,unsigned long,unsigned short,struct tagDISPPARAMS *,struct tagVARIANT *,struct tagEXCEPINFO *,unsigned int *)    Unknown
     clr.dll!Dispatch_Invoke_CallBack(void *)    Unknown
     clr.dll!Dispatch_Invoke_Wrapper(struct IDispatch *,long,struct _GUID const &,unsigned long,unsigned short,struct tagDISPPARAMS *,struct tagVARIANT *,struct tagEXCEPINFO *,unsigned int *)    Unknown
     partbrpD.dll!_com_invoke_helper(IDispatch * pDispatch, long dwDispID, unsigned short wFlags, unsigned short vtRet, void * pvRet, const wchar_t * pwParamInfo, char * argList, IErrorInfo * * pperrinfo) Line 322    C++
     partbrpD.dll!_com_dispatch_method(IDispatch * pDispatch, long dwDispID, unsigned short wFlags, unsigned short vtRet, void * pvRet, const wchar_t * pwParamInfo, ...) Line 83    C++
     partbrpD.dll!ExcelReader::GetExcelSheetCount(_bstr_t Filename, long * nSheets) Line 16    C++
     partbrpD.dll!JMReadHoleThreadStandardsFile_OpenXML2(GUserFileName excelFile, int isheet, int * pStatus, bool bReadingFromThread) Line 4792    C++
     partbrpD.dll!UJMReadHoleThreadStandardInfo(GUserText standard, int isheet, int * pStatus) Line 10822    C++
     partbrpD.dll!ReadDBSheetProc(void * pParam) Line 10869    C++
     mfc140ud.dll!_AfxThreadEntry(void * pParam) Line 109    C++
     ucrtbased.dll!00007ff8aa122ec5()    Unknown
     ToolkitPro2410vc170x64UD.dll!CXTPSkinManagerDetoursApiHook::ThreadProcHook(void * lpThreadData) Line 603    C++


Notice that thread is also calling:

XTP_EXT_CLASS CXTPSkinManager* AFX_CDECL XTPSkinManager()
{
    XTP_SKINFRAMEWORK_GLOBALLOCK_SHARED_SCOPE();

    if (CXTPSkinManager::s_pInstance == NULL)
    {
        CXTPSkinManager::s_pInstance = &XTPSkinManagerSingleton::Instance();
    }

    return CXTPSkinManager::s_pInstance;
}

Setting breakpoints I see the main thread is in the loop. Meanwhile the second thread never returns from the RtlpWaitOnCriticalObject.

Since we have entered idle processing and we are a COM app, the OS is freeing unused libraries. That goes thru _AfxCrtDumpClient which is what the main thread is hooking into when memory leak detection is running and the call to get the mscoree.dll is made:

void __cdecl _AfxCrtDumpClient(void * pvData, size_t nBytes)
{
    if(_CrtReportBlockType(pvData) != _AFX_CLIENT_BLOCK)
        return;
    char sz[256];
    CObject* pObject = (CObject*)pvData;
    bool fCLRPresent=(::GetModuleHandleW(L"mscoree.dll")!=NULL);

All other ToolkitPro threads look standard and are all "small stacks" waiting on an object.

When this happens all I can do is restart.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net