.NET Zone is brought to you in partnership with:

Sasha Goldshtein is a Senior Consultant for Sela Group, an Israeli company specializing in training, consulting and outsourcing to local and international customers.Sasha's work is divided across these three primary disciplines. He consults for clients on architecture, development, debugging and performance issues; he actively develops code using the latest bits of technology from Microsoft; and he conducts training classes on a variety of topics, from Windows Internals to .NET Performance. You can read more about Sasha's work and his latest ventures at his blog: http://blogs.microsoft.co.il/blogs/sasha. Sasha writes from Herzliya, Israel. Sasha is a DZone MVB and is not an employee of DZone and has posted 159 posts at DZone. You can read more from them at their website. View Full User Profile

Sync Block Diagnostics with PSSCor2 (or PSSCor4)

09.30.2012
| 1472 views |
  • submit to reddit

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 
0:011> !syncblk 
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

Published at DZone with permission of Sasha Goldshtein, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)