Monday, 24 September 2012

Debugging Concurrent Code in VS 2012

Visual Studio 2012 comes with some enhanced debugger features that help when debugging parallel code.

We can see this by running the C# Blender example.

You can see Threads and Tasks using the debug windows.

Here is the Parallel Tasks view, you can get it with Debug > Windows > Parallel Tasks


You can also launch a Parallel Watch window with Debug > Windows > Parallel Watch
You can enter watch expressions and see their evaluation under multiple tasks, here we examine num.

Another feature is the Parallel Stacks, here you can see the main thread stack along with the fork join example and its spawned threads.


There is also a concurrency visualizer that allows to see if you are making good use of you machines cores, it mainly shows occupancy, but you can also see events and locks.

The following picture shows the result of running the Thread pool blender followed by the sequential blender. You can see that we get good occupancy with the thread pool followed by a period of inactivity, followed by the sequential version which fully occupies just one core.




This image shows the four threads in green that are occupying the four cores of the machine, along with 9 blocked threads in red, one UI thread in brown, and one thread sleeping. 



That concludes a brief overview of the concurrency features in the Visual Studio 2012 debugger.

No comments:

Post a Comment