Login | Register
Login | Register

My pages Projects SunSource.net openCollabNet
OpenSPARC.net >  Cool Tools >  Thread Analyzer > 

Cool Tools - Thread Analyzer

About the Thread Analyzer

The Thread Analyzer is a tool that analyzes the execution of a multi-threaded program and checks for a variety of multi-threaded programming errors such as data races and deadlocks. The tool is part of the Sun Studio software, starting with Sun Studio 12.

The tool can detect errors in codes that are written using the POSIX thread API, the Solaris Operating System® thread API, OpenMP API, Sun parallel directives, Cray® parallel directives, or a mix of these.

Data Races

A data-race occurs when:

  • Two or more threads in a single process access the same memory location concurrently,
  • At least one of the accesses is for writing, and
  • The threads are not using any exclusive locks to control their accesses to that memory.

When these three conditions hold, the order of accesses is non-deterministic. Therefore each run can give different results depending on the order of the accesses. Some data-races may be benign (for example, when the memory access is used for a busy-wait), but many data-races are either bugs or caused by bugs in the program.

Deadlocks

Deadlock describes a condition where two or more threads are blocked (hang) forever, waiting for each other. Suppose we have a process with two or more threads. A deadlock occurs when the following three conditions hold:

  • Threads already holding locks request new locks,
  • The requests are made concurrently, and
  • Two or more threads form a circular chain where each thread waits for a lock that the next thread in the chain holds.

Here is an example of a deadlock condition:

Thread 1: holds lock A, requests lock B
Thread 2: holds lock B, requests lock A

A deadlock can be of two types: A "potential deadlock" or an "actual deadlock". A potential deadlock is a deadlock that did not occur in a given run, but can occur in different runs of the program depending on the timings of the requests for locks by the threads. An actual deadlock is one that actually occured in a given run of the program. An actual deadlock causes the threads involved to hang, but may or may not cause the whole process to hang.

A deadlock can be of two types: A "potential deadlock" or an "actual deadlock". A potential deadlock is a deadlock that did not occur in a given run, but can occur in different runs of the program depending on the timings of the requests for locks by the threads. An actual deadlock is one that actually occured in a given run of the program. An actual deadlock causes the threads involved to hang, but may or may not cause the whole process to hang.

Platforms

The Thread Analyzer supports the following hardware and operating systems:

  • The SPARC® v8plus, v8plusa, v8plusb, v9, v9a, and v9b architectures
  • The Intel® x86 and AMD® x64 platforms
  • The Solaris 9, Solaris 10, and Linux operating systems
  • The SuSE Linux Enterprise Server 9 and Red Hat Enterprise Linux 4 operating systems

Download and Install

You can use either the GCC for SPARC® Systems compilers, or the Sun Studio compilers, to compile your codes. For data race detection, be sure to compile with the -xinstrument=datarace compiler option to instrument your code.

To download and install the GCC for SPARC® Systems compiler, follow the instructions on the GCC for SPARC® Systems page.

To download and install the Sun Studio software (includes Sun Studio compilers and the Thread Analyzer), follow the instructions on the Sun Studio downloads page.

Features

The Thread Analyzer includes the following features:

  • The new compiler option -xinstrument=datarace which instruments the source code for data race detection. See tha.1 for more information. Note that no special compiler option is needed for deadlock detection.
  • User APIs to notify the Thread Analyzer of user-implemented custom synchronization schemes.
  • Command line and GUI tools interfaces to create an experiment and examine the results.

Documentation

  • The main reference manual for using the Thread Analyzer is the Sun Studio Thread Analyzer User's Guide. This manual includes tutorials on data race detection and deadlock detection.
  • The following man pages are also available:
    • analyzer.1 - analyze experiment results
    • collect.1 - collect experiment data
    • collector.1 - dbx subcommands for performance data collection
    • er_print.1 - print a report from one or more experiments
    • libtha.3 - API for the Thread Analyzer
    • tha.1 - analyze a Thread Analyzer experiment

Questions and Feedback

Sign on to the Sun Studio Tools Forum to post questions to Sun engineering and the community. You might find that your problem has already been solved.