Alternative title: yet another another another way to determine the sync object for which your thread is waiting. I should make a series out of these posts, as there are at least four distinct approaches now.
In case you haven’t seen them, PSSCor2 and PSSCor4 are WinDbg extensions that augment and extend SOS functionality for .NET 2.0 and 4.0 applications, respectively. They don’t ship with the .NET Framework (unlike SOS), but you can find them online.
To the case in point, PSSCor2/4 provides a command called !SyncBlk (akin to SOS’s command with the same name), which outputs the list of threads waiting for each of the locked sync blocks in your program. This is a one-stop shop for all Monitor-related deadlock and wait chain diagnostics, out of the box.
Here’s an example from a 64-bit app (the command output was edited to fit the screen):
0:011> .load C:\…\psscor2\amd64\psscor2
Index Owning Thread Info
18 00000000007f2e40 1da8 0
Waiting threads: 4
19 000000001bbe14a0 185c 4
Waiting threads: 0
The output immediately shows the locked sync blocks as well as the threads that are blocked waiting for them. Owning thread information provides the deadlocked wait chain immediately:
Thread 0 –> Sync Block 19 –> Thread 4 –> Sync Block 18 –> Thread 0