Joseph,
I came across this problem recently. The negative lock count is due to the changed encoding of that field starting with Windows Server 2003 SP1. There is a note about this in the online help of WinDBG (in the critical section decription) that also describes how to de-code the real values from the lock count field. Here is the relevant section from the help file:
<<<<<<<<<<<<<<<<< BEGIN QUOTE >>>>>>>>>>>>>>>>>>>>>>>
Interpreting Critical Section Fields in Windows Server 2003 SP1 and Later
In Microsoft Windows Server 2003 Service Pack 1 and later versions of Windows, the LockCount field is parsed as follows:
The lowest bit shows the lock status. If this bit is 0, the critical section is locked;
if it is 1, the critical section is not locked. The next bit shows whether a thread has been woken for this lock. If this bit is 0, then a thread has been woken for this lock; if it is 1, no thread has been woken. The remaining bits are the ones-complement of the
number of threads waiting for the lock.
As an example, suppose the LockCount is -22. The lowest bit can be determined in this way:
0:009> ? 0x1 & (-0n22)
Evaluate expression: 0 = 00000000
The next-lowest bit can be determined in this way:
0:009> ? (0x2 & (-0n22)) >> 1
Evaluate expression: 1 = 00000001
The ones-complement of the remaining bits can be determined in this way:
0:009> ? ((-1) - (-0n22)) >> 2
Evaluate expression: 5 = 00000005
In this example, the first bit is 0 and therefore the critical section is locked. The second
bit is 1, and so no thread has been woken for this lock. The complement of the remaining bits is 5, and so there are five threads waiting for this lock. <<<<<<<<<<<<<<<<< END QUOTE >>>>>>>>>>>>>>>>>>>>>>>
The documentation clearly states "Windows Server 2003 SP1 and Later" so all Windows Server 2003 before that will ise the older format
Kind Regards
Frank
-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Joseph Galbraith
Sent: Thursday, February 15, 2007 1:10 AM
To: Kernel Debugging Interest List
Subject: [windbg] Critical section documentation...
The documentation about critical sections
(Build date June 30, 2006, Topic Title: Displaying a Critical)
mentions one interpretation for NT 4.0, Windows 2000, and Windows XP and one for Windows Server 2003 Service Pack 1 ... however, it is unclear to me which format Windows Server 2003 (RTM) uses?
I'm trying to write some ASSERTs about the state of my critical sections in debug builds (for example, that it isn't locked when I'm calling ::DeleteCriticialSection().)
From my reading of the topic mentioned, it appears that
it is an invalid state for the lock count to be other
than -1 when OwningThread is 0. Can anyone confirm this?
I saw this during a debugging session the other day
(owning thread was 0 and LockCount was 5.) I suspect
this situation may indicate that the LeaveCriticalSection
was called more times than EnterCriticalSection. Can any confirm this?
Thanks,
Jsoeph
You are currently subscribed to windbg as: xxxxx@oracle.com To unsubscribe send a blank email to xxxxx@lists.osr.com