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, you can navigate between threads. When you select a different thread from the Thread drop-down list, the Call Stack will be updated with the selected thread's execution path, and the execution point moved to the current location in the source code. In Figure 45-14 we have also filtered the list of threads to show only those we have flagged. This is done using the button with the double-flag icon, next to the Threads drop-down.

Figure 45.14. Figure 45-14

Although these features do not make it totally simple to debug multi-threaded applications, they do solve one of the more significant issues, which is keeping track of individual threads and where they are up to in your application.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.133.61