Sun Studio 12: Thread Analyzer User's Guide

3.3 How to Use the Thread Analyzer to Find Deadlocks

You can use the thread Analyzer to check for potential and actual deadlocks in your program. The Thread Analyzer follows the same "collect-analyze" model that the Sun Studio Performance Analyzer uses. There are three steps involved in using the Thread Analyzer:

3.3.1 Compile the Source Code

Compile your code and be sure to specify -g. Do not specify a high-level of optimization because information such as line numbers and callstacks, may be reported incorrectly at a high optimization level. Compile an OpenMP program with -g -xopenmp=noopt, and compile a POSIX threads program with just -g -mt.

See cc.1, CC.1, or f95.1 for more information.

3.3.2 Create a Deadlock-Detection Experiment

Use the Thread Analyzer's collect command with the -r deadlock option. This option creates a deadlock-detection experiment during the execution of the program.

You can increase the likelihood of detecting deadlocks by creating several deadlock-detection experiments. Use a different number of threads and different input data for the various experiments.

See collect.1 and collector.1 for more information.

3.3.3 Examine the Experiment Results

You can examine the deadlock-detection experiment with either the tha command, the analyzer command, or the er_print utility. Both the Thread Analyzer and the Analyzer present a GUI interface while er_print employes a command-line interface.

See tha.1, analyzer.1, and er_print.1 for more information.

3.3.3.1 The Thread Analyzer Interface

The Thread Analyzer includes a menu bar, a tool bar, and a split pane that contains tabs for the various displays. The following three tabs are shown by default in the left-hand pane:

3.3.3.2 The er_print Interface

In contrast to the left-hand pane, the right-hand pane contains the Deadlock Details tab which shows detailed information for the selected thread in the Deadlocks tab. The most useful subcommands for examining deadlocks with er_print are the following:

See er_print.1 for more information.