While debugging with the SOS extension, I used the SyncBlk command and got
the following output.
0:003> !SyncBlk
Index SyncBlock MonitorHeld Recursion   Thread  ThreadID     Object Waiting
    3 0016f634            3         1   161a50   910   4   00aa1bac
System.Object
                Waiting threads:
    4 0016f660            3         1   161888   d08   3   00aa1ba0
System.Object
                Waiting threads:

I was curious to know what that MonitorHeld column was - and dug through the
Rotor sos code and found that it mapped to the m_MonitorHeld of AwareLock.

The lines of code that interest me are (in SyncBlk.cpp)

FastInterlockCompareExchange((LONG*)&m_MonitorHeld, state + 2, state) (which
gets executed whenever tries to acquire a lock)

And

FastInterlockCompareExchange((LONG*)&m_MonitorHeld, state - 2, state)
(inside AwareLock::EnterEpilog)

Whenever you get a new guy waiting on the lock, the state variable (which is
the same as the m_MonitorHeld) gets bumped up by 2 and bumped back down by 2
whenever someone stops waiting.

When someone *does* acquire the lock, the code executed is
(FastInterlockCompareExchange((LONG*)&m_MonitorHeld, ((state - 2) | 1),
state).

Now, here are my questions

1. Why is the number bumped up by 2 every time someone waits on the lock?

2. What is the meaning of doing (state - 2) | 1) - and why?

3. How do I translate the MonitorHeld column in the !SyncBlk command? Do I
assume that every 2 incrememnt after 1 corresponds to some guy waiting?


Thanks in advance,
Sriram


----------------------------------------------------------------------------
-

I blog at http://www.dotnetjunkies.com/weblog/sriram

----------------------------------------------------------------------------

===================================
This list is hosted by DevelopMentorŪ  http://www.develop.com
ASP.NET courses you may be interested in:

Guerrilla.NET Sept 27-Oct 1, in Torrance
http://www.develop.com/courses/gdotnetls

Essential.NET Sept 20-24, in San Francisco
Essential.NET Oct. 4-8, in London
http://www.develop.com/courses/edotnet


View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to