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:
Compile the source code.
Create a deadlock-detection Experiment.
Examine the experiment results.
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.
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.
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.
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:
The Deadlocks tab
This tab shows a list of potential and actual deadlocks that the Thread Analyzer detected in the program. This tab is selected by default. The threads involved for each deadlock are shown. These threads form a circular chain where each thread holds a lock and requests another lock that the next thread in the chain holds.
The Dual Source tab
Select a thread in the circular chain and then click on the Dual Source tab. The Dual Source tab shows the source location where the thread held a lock, and the source location where the same thread requested a lock. The source lines where the thread held and requested locks are highlighted.
The Experiments tab
This tab shows the load objects in the experiment, and lists any error and warning messages. The following two tabs are shown on the right-hand pane of the Thread Analyzer display:
The Summary tab which shows summary information about a deadlock selected from the Deadlocks tab.
The Deadlock Details tab which shows detailed information about a thread context selected from the Deadlocks tab.
er_print
InterfaceIn 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:
-deadlocks
The option reports any potential and actual deadlocks detected in the experiment.
-ddetail deadlock_id
This option
returns detailed information about the deadlock with the specified deadlock_id. If you specify the value all as the deadlock_id, then er_print
displays detailed information
about all deadlocks.
-header
This option displays descriptive information about the experiment and reports any errors or warnings.
See er_print.1 for more information.