views:

92

answers:

2

when I ssued !syncblk command on a deadlocked application from windbg, I got the following output. It shows which thread holds the lock. But it does not indicate which threads are waiting for the lock. How can I identify the threads that are waiting? .

0:004> !syncblk 
Index SyncBlock MonitorHeld Recursion Owning Thread Info SyncBlock Owner 
2      0016d12c  3           1        0014b1c0 1ab8 0    01292e3c System.Object 
----------------------------- 
Total 2 
CCW 0 
RCW 0 
ComClassFactory 0 
Free 0 
+2  A: 

You could look at all of the managed stacks using ~*e!clrstack. If a thread is waiting to acquire a lock, you should see some appropriate frames in it's stack (e.g, Monitor.TryEnter).

Liran
A: 

If you're troubleshooting a deadlock problem, your first action should be to load SOSEX.dll and try the !dlk command, as it will identify deadlocks based on Monitor and ReaderWriteLock. It will even pinpoint the exact spot in the source code.

In some cases the !dlk command doesn't identify deadlocks as expected. In that case you need to use !syncblock as per your question. To find what thread is trying to acquire a specific lock, you can use ~*e!clrstack as @Liran points out. However, you can also use ~*e!dso (which will dump references on the stack for the different threads) and look for references to the lock object.

Brian Rasmussen