Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
106 lines (77 sloc) 6.34 KB
title ms.topic f1_keywords dev_langs helpviewer_keywords ms.assetid caps.latest.revision author manager
Debug Multithreaded Applications
threading [Visual Studio], debugging
debugging [Visual Studio], high-performance computing
debugging [Visual Studio], multithreaded
multithreaded debugging
high-performance debugging

Debug Multithreaded Applications in Visual Studio


A thread is a sequence of instructions to which the operating system allocates processor time. Every process that is running in the operating system consists of at least one thread. Processes that have more than one thread are called multithreaded.

Computers with multiple processors, multi-core processors, or hyperthreading processes can run multiple threads at the same time. Parallel processing of multiple threads can greatly improve program performance, but it can also make debugging more difficult because it introduces the need to keep track of multiple threads.

In addition, multithreading introduces some new types of potential bugs. Often, for example, two or more threads have to access the same resource, but only one thread can safely access the resource at a time. Some form of mutual exclusion is necessary to make sure that only one thread is accessing the resource at a time. If mutual exclusion is performed incorrectly, it can create a deadlock condition where no thread can execute. Deadlocks can be a particularly hard problem to debug.

Visual Studio provides a Threads window, a GPU Threads window, a Parallel Watch window, and other features that make multithreaded debugging easier. The best way to learn about the threading features is by doing the walkthroughs. See Walkthrough: Debugging a Multithreaded Application and Walkthrough: Debugging a C++ AMP Application.

Visual Studio also provides powerful breakpoints and tracepoints, which can be very useful when you debug multithreaded applications. You can use breakpoint filters to place breakpoints on individual threads. See Using Breakpoints

Debugging a multithreaded application that has a user interface can be especially difficult. In that case, you might consider running the application on a second computer and using remote debugging. For information, see Remote Debugging.

In This Section

Debug Threads and Processes Explains the basics of debugging threads and processes.

Debug Multiple Processes Explains how to debug multiple processes.

How to: Use the Threads Window Useful procedures for debugging threads with the Threads window.

How to: Switch to Another Thread While Debugging Three ways to switch the debugging context to another thread.

How to: Flag and Unflag Threads Mark or flag threads that you want to give special attention to while debugging.

How to: Set a Thread Name in Native Code Give your thread a name that you view in the Threads window.

How to: Set a Thread Name in Managed Code Give your thread a name that you view in the Threads window.

Walkthrough: Debugging a Multithreaded Application. A guided tour of thread debugging features, with emphasis on features how to [!INCLUDEvs_orcas_long].

How to: Debug On a High-Performance Cluster Techniques for debugging an application that runs on a high-performance cluster.

Tips for Debugging Threads in Native Code Simple techniques that can be useful for debugging native threads.

Using the Tasks Window Shows a list of all the managed or native task objects including their status and other useful info.

Using the Parallel Stacks Window Shows call stacks of multiple threads (or tasks) in a single view and it also coalesces stack segments that are common amongst the threads (or tasks).

Walkthrough: Debugging a Parallel Application Walkthrough that shows how to use the Parallel Tasks and Parallel Stacks windows.

How to: Use the Parallel Watch Window Inspect values and expressions across multiple threads.

How to: Use the GPU Threads Window Examine and work with threads that are running on the GPU during debugging.

Related Sections

Using Breakpoints

See Also

Debug Threads and Processes Remote Debugging

You can’t perform that action at this time.