简体   繁体   English

转储关键节队列(线程正在等待)

[英]Dump Critical Section Queue (Threads waiting)

I have an issue (crash dump) where my Critical Section is being destroyed but after inspecting the LockCount I note that there is 1 thread waiting on it (it seems that the thread has been woken, but not yet entered, since lock status is Not Locked). 我有一个问题(崩溃转储),我的关键部分被破坏了,但是在检查LockCount之后,我注意到有1个线程在等待它(似乎该线程已被唤醒,但尚未进入,因为锁定状态为Not已锁定)。

I want to see what thread has been woken. 我想看看什么线程被唤醒。 I know the Critical Section has a queue of waiting threads, if I could dump this queue/list structure I should be able to answer my question, any idea's on what I could do? 我知道关键部分有一个等待线程的队列,如果我可以转储此队列/列表结构,我应该可以回答我的问题,关于我能做什么的任何想法?

the CriticalSection Object is defined as CriticalSection对象定义为

typedef RTL_CRITICAL_SECTION CRITICAL_SECTION;

with RTL_CRITICAL_SECTION defined as RTL_CRITICAL_SECTION定义为

typedef struct _RTL_CRITICAL_SECTION {
    PRTL_CRITICAL_SECTION_DEBUG DebugInfo;
    LONG LockCount;
    LONG RecursionCount;
    HANDLE OwningThread;        // from the thread's ClientId->UniqueThread
    HANDLE LockSemaphore;
    ULONG_PTR SpinCount;        // force size on 64-bit systems when packed
} RTL_CRITICAL_SECTION, *PRTL_CRITICAL_SECTION;

OwningThread will contain a handle to the owning thread. OwningThread将包含拥有线程的句柄。 So you may just read the CriticalSection data structure to obtain the handle to the owning thread. 因此,您可以只读取CriticalSection数据结构来获取拥有线程的句柄。

DWORD WINAPI GetThreadId(_In_ HANDLE OwningThread);

will return the ID of the owning thread. 将返回拥有线程的ID。

However, there is a small mishap with the definition of OwningThread. 但是,OwningThread的定义有一个小麻烦。 MSDN reports that field actually contains the thread ID itself. MSDN报告该字段实际上包含线程ID本身。

You may use 您可以使用

GetThreadInformation(OwningThread,....);

to obtain more thread details. 获取更多线程详细信息。

Break Free of Code Deadlocks in Critical Sections Under Windows on MSDN is a must read in this context. 在这种情况下, 必须阅读 Windows上MSDN上关键部分中的代码死锁 Particulary the EntryCount/ContentionCount field in the RTL_CRITICAL_SECTION_DEBUG structure may give an answer to the question here. 格外的EntryCount/ContentionCount领域RTL_CRITICAL_SECTION_DEBUG结构可能会给出一个答案,这里的问题。

Have you tried !locks? 您尝试过!锁吗? There's info about viewing critical sections in a process in the WinDBG docs here: 这里有有关在WinDBG文档中查看过程中关键部分的信息:

http://msdn.microsoft.com/en-us/library/windows/hardware/ff541979(v=vs.85).aspx http://msdn.microsoft.com/zh-CN/library/windows/hardware/ff541979(v=vs.85).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM