Debug multithreaded applications in Visual Studio

A thread is a sequence of instructions to which the operating system grants 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 several simultaneous threads. Parallel processing using many threads can greatly improve program performance, but it may also make debugging more difficult because you're tracking many threads.

Multithreading can introduce new types of potential bugs. For example, two or more threads may need to access the same resource, but only one thread at a time can safely access the resource. Some form of mutual exclusion is necessary to make sure that only one thread is accessing the resource at any time. If mutual exclusion is implemented incorrectly, it can create a deadlock condition where no thread will execute. Deadlocks are often a hard problem to debug.

Tools for debugging multithreaded apps

Visual Studio provides different tools for use in debugging multithreaded apps.

Visual Studio also provides powerful breakpoints and tracepoints, which can be useful when you debug multithreaded applications. Use breakpoint conditions and filters to place breakpoints on individual threads. Tracepoints enable you to trace execution of your program without breaking, to study problems such as deadlocks. For more information, see Breakpoint actions and tracepoints.

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

Articles about debugging multithreaded apps