0

我有一个问题(崩溃转储),我的关键部分被破坏但在检查 LockCount 后我注意到有 1 个线程在等待它(似乎线程已被唤醒,但尚未进入,因为锁定状态不是锁定)。

我想看看哪个线程被唤醒了。我知道关键部分有一个等待线程队列,如果我可以转储这个队列/列表结构,我应该能够回答我的问题,有什么想法可以做吗?

4

2 回答 2

0

the CriticalSection Object is defined as

typedef RTL_CRITICAL_SECTION CRITICAL_SECTION;

with RTL_CRITICAL_SECTION defined as

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. So you may just read the CriticalSection data structure to obtain the handle to the owning thread.

DWORD WINAPI GetThreadId(_In_ HANDLE OwningThread);

will return the ID of the owning thread.

However, there is a small mishap with the definition of OwningThread. MSDN reports that field actually contains the thread ID itself.

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. Particulary the EntryCount/ContentionCount field in the RTL_CRITICAL_SECTION_DEBUG structure may give an answer to the question here.

于 2012-08-17T09:05:36.010 回答
0

你试过!锁吗?在 WinDBG 文档中有关于查看进程中的关键部分的信息:

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

于 2012-08-17T15:21:59.813 回答