Understanding Wait Chain Traversal

This article describes the new wait chain traversal (WCT) functionality in Windows Server® 2008. A detailed discussion on debugging applications using this feature can be found in the companion topic Developing with Wait Chain Traversal.

Wait Chain Traversal

Applications use synchronization objects, such as critical sections, to control access to shared resources. Applications can suspend execution of threads and processes while waiting to acquire synchronization objects or while waiting for a thread or process to finish executing. Race conditions and failure to release synchronization objects can lead to threads and processes hanging indefinitely. Applications can also end up in a deadlocked state where dependency requirements cannot be satisfied. For example, consider an application with two threads (A and B) and two synchronization objects (1 and 2). If Thread A has Object 1 and is blocked waiting for Object 2, while Thread B has Object 2 and is blocked waiting for Object 1, the threads are said to be deadlocked.

Wait chain traversal (WCT) is a mechanism for debugging blocked threads and processes, and detecting deadlocks. WCT currently supports debugging threading issues involving the following:

  • ALPC

  • COM

  • Critical sections

  • Mutual exclusions (mutexes)

  • SendMessage

  • Wait operations on processes and threads

Using WCT, debugging software can analyze executing processes and report on the state of threads, including information such as what a blocked thread is waiting for and whether a deadlock condition exists. WCT allows debugging software to detect problems both within and across process boundaries.

Debugging software first identifies the processes and threads to analyze and then reports the state of threads in one or more processes. A thread's state (unblocked, blocked, or deadlocked) is reported as a wait chain. A wait chain is an alternating directed graph of threads and synchronization objects. In the graph, an edge from a thread to an object indicates that the thread is waiting for the object; an edge from an object to a thread indicates that the thread is the current owner of the object. For example, the following wait chain represents a thread (Thread A) that is blocked waiting for a mutex object that is owned by Thread B.

Thread A → Mutex 1 → Thread B

As illustrated here, the first node in a wait chain is the thread being analyzed and the remaining nodes are the elements (synchronization objects, processes, threads, and so on), if any, that are directly or indirectly causing the thread to block. The simplest wait chain reflects a thread that is not blocked. It is composed of a single node, representing the unblocked thread. A blocked thread is represented by a wait chain containing multiple nodes that is non-cyclic: that is, there are no two nodes in the chain that represent the same thread or object. When a thread is deadlocked, the wait chain that represents it is cyclic. Consider the scenario where Thread A owns Object 1 and is blocked waiting for Object 2, while Thread B owns Object 2 and is blocked waiting for Object 1. The wait chain is as follows:

Thread A → Object 2 → Thread B → Object 1 → Thread A

Note that Thread A appears twice. The second node for Thread A could be replaced by an edge (→) that connects Object 1 to the first Thread A node, creating a loop that represents the cyclic dependency.

See Also

Concepts

Developing with Wait Chain Traversal

Wait Chain Traversal

Other Resources

About Synchronization