在什么情况下 Windows 关键部分的锁定计数可能为负数?
Windows 中 RTL_CRITICAL_SECTION 结构的 LockCount 字段是否可以合法为负数?
我们正在跟踪一次非常难以捉摸的崩溃,我们看到的一个症状是 CS 的 LockCount 为负值。崩溃时,计数为 -6,但通常似乎为 -1、-2 等。
在假设发生这种情况是一件非常糟糕的事情之前,我只是去追赶它想要验证这个假设是否正确。我几乎找不到有关 RTL_CRITICAL_SECTION 内部工作原理的信息。
Is there any circumstance in which the LockCount field of a RTL_CRITICAL_SECTION structure in Windows can legitimately be negative?
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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在某些 Windows 版本上,负锁定计数是正常行为。请注意,该字段的含义在 Windows 的生命周期中发生了变化(见下文)。
解释这些私有字段是一件棘手的事情,您可能会从使用专用的关键部分调试工具中受益。
例如,请参阅这篇 MSDN 文章,其中提供了一些详细信息。特别是,我认为它说明了为什么值 -6 是完全合理的。
一些相关摘录:
然后继续解释如何解释
-22
的锁定计数。因此,总而言之,这比您想象的要棘手!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).
Interpreting these private fields is a tricky business and you may benefit from using dedicated critical section debugging tools.
For example, see this MSDN article gives some details. In particular I think it shows why a value of -6 is perfectly plausible.
Some pertinent excerpts:
It then goes on to explain how to interpret a lock count of
-22
. So, in summary, it's trickier than you might think!此处是部分说明:
From here, is a part explanation: