Sun Studio 12: Thread Analyzer User's Guide

2.2.1 Instrument the Source Code

In order to enable data-race detection in a program, the source files must first be compiled with a special compiler option. This special option for the C, C++, and Fortran languages is: -xinstrument=datarace

Add the -xinstrument=datarace compiler option to the existing set of options you use to compile your program. You can apply the option to only the source files that you suspect to have data-races.


Note –

Be sure to specify -g when you compile your program. Do not specify a high level of optimization when compiling your program for race detection. Compile an OpenMP program with -xopenmp=noopt. The information reported, such as line numbers and callstacks, may be incorrect when a high optimization level is used.


The following are example commands for instrumenting the source code: