45.5. Multi-Threaded Debugging

Multi-threaded applications have traditionally been notoriously difficult to debug properly. Seemingly fundamental tasks, such as keeping track of which thread you are currently inspecting and what other threads are currently executing, are some of the reasons why this task is so hard. Fortunately, Visual Studio 2008 has improved the support available for debugging multi-threaded applications.

In Chapter 41 we discussed the Threads debug window, which lists all the active threads for a particular application. New functionality accessed through this window includes the ability to set a friendly name for a thread. You can also set flags on individual threads, which means that you don't have to spend as much time trying to keep track of thread IDs.

To further improve debugging, you can now identify each thread within the source code editor window. This is enabled from the Threads window, by right-clicking any entry and selecting Show Threads in Source. The result of this is shown in Figure 45-13, where a new thread marker icon (consisting of a red and blue wavy line) is displayed in the gutter. The thread marker indicates that a thread, or several threads, is stopped at this location. When you hover over the thread marker a tooltip will be displayed that identifies which threads are stopped here. The thread names listed are the friendly names that have been entered in the Threads window.

Figure 45.13. Figure 45-13

Within the Debug Location Toolbar, ...

Get Professional Visual Studio® 2008 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.