在什么情况下会在Windows临界区有负面锁计数? [英] Under what circumstances might a Windows Critical Section have a negative Lock Count?

查看:246
本文介绍了在什么情况下会在Windows临界区有负面锁计数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有在Windows中的RTL_CRITICAL_SECTION结构的锁定计数字段可以合法地是负任何情况下?

Is there any circumstance in which the LockCount field of a RTL_CRITICAL_SECTION structure in Windows can legitimately be negative?

我们正在跟踪一个非常难以捉摸的崩溃和一个症状,我们所看到的是一个负锁定计数的CS。在崩溃之时,计数为-6,但它似乎经常是-1,-2,等等。

We're tracking a VERY elusive crash and one symptom we're seeing is a CS with a negative LockCount. At the time of the crash, the count is -6, but it seems to routinely be -1, -2, etc.

在去假设它是这个非常糟糕的事情发生后追了,我只是想验证这种假设是正确的。我能找到一点上RTL_CRITICAL_SECTION的内部工作的信息。

Before go chasing off after that on the assumption that it is a Very Bad Thing for this to occur, I just want to verify that that assumption is correct. I can find little to no information on the inner workings of RTL_CRITICAL_SECTION.

推荐答案

负锁定计数是一些Windows版本的正常行为。请注意,此字段的意义的Windows的寿命期间发生了变化(见下文)。

Negative lock count is normal behaviour on some Windows versions. Note that the meaning of this field has changed during the lifetime of Windows (see below).

国米preting这些私人领域是一个棘手的业务,你可以使用专用的关键部分调试工具中获益。

Interpreting these private fields is a tricky business and you may benefit from using dedicated critical section debugging tools.

例如,看到这个 MSDN文章给出了一些细节。特别是我认为这说明了为什么-6的值是完全有道理的。

For example, see this MSDN article gives some details. In particular I think it shows why a value of -6 is perfectly plausible.

一些中肯的摘录:

临界区可以通过各种不同的方法被显示在用户模式。每个字段的确切含义取决于Microsoft Windows版本的版本所使用。

Critical sections can be displayed in user mode by a variety of different methods. The exact meaning of each field depends on the version of Microsoft Windows version you are using.

......

在Microsoft Windows 2000和Windows XP中,锁定计数字段表示,任何线程调用EnterCriticalSection的例行此临界段时间,数减一。该字段开始于-1一个上锁的关键部分。 EnterCriticalSection的每个调用都会递增该值; LeaveCriticalSection每次调用递减它。例如,如果锁定计数是5,这临界区被锁定,一个线程已获得它,而另外五个线程正在等待这个锁。

In Microsoft Windows 2000, and Windows XP, the LockCount field indicates the number of times that any thread has called the EnterCriticalSection routine for this critical section, minus one. This field starts at -1 for an unlocked critical section. Each call of EnterCriticalSection increments this value; each call of LeaveCriticalSection decrements it. For example, if LockCount is 5, this critical section is locked, one thread has acquired it, and five additional threads are waiting for this lock.

......

在Microsoft Windows Server 2003 Service Pack 1和更高版本
  Windows中,锁定计数域分析如下:

In Microsoft Windows Server 2003 Service Pack 1 and later versions of Windows, the LockCount field is parsed as follows:


      
  • 的最低位显示锁定状态。如果该位为0时,临界
      部分被锁定;如果它是1,临界段未锁定。

  •   
  • 下位显示了一个线程是否已经唤醒了这个锁。如果
      该位是0,那么线程已经唤醒这个锁;如果它是1,
      没有线程已经唤醒。

  •   
  • 剩余的位是线程数的个补
      等待锁。

  •   

然后它接着解释如何跨preT -22 的锁定计数。所以,总的来说,这是棘手比你想象!

It then goes on to explain how to interpret a lock count of -22. So, in summary, it's trickier than you might think!

这篇关于在什么情况下会在Windows临界区有负面锁计数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆