Tips for instrumenting an application for data race detection before collecting an experiment:
If you get an error message from the compiler saying that the compiler option -xinstrument=datarace is illegal, you are using an older version of the Sun Studio compiler that does not support the Thread Analyzer. You can check the version of the compiler you are using by typing the command cc -Version. The earliest version that supports Thread Analyzer is dated June 2006.
The collect -r race command issues a warning if the binary is not instrumented for data race detection, as shown here:
% collect -r races a.out WARNING: Target `a.out' is not instrumented for datarace detection; reported datarace data may be misleading
You can determine whether a binary is instrumented for data race detection by using the nm command and looking for calls to tha routines. If routines whose names begin with __tha_ are shown, the binary is instrumented. Example output is shown below.
% cc -xopenmp -g -xinstrument=datarace source.c % nm a.out | grep __tha_  | 135408| 0|FUNC |GLOB |0 |UNDEF |__tha_get_stack_id  | 135468| 0|FUNC |GLOB |0 |UNDEF |__tha_src_read_w_frame  | 135444| 0|FUNC |GLOB |0 |UNDEF |__tha_src_write_w_frame
% cc -xopenmp -g source.c % discover -i datarace -o a.out.i a.out % nm a.out.i | grep __tha_  | 0| 0|NOTY |GLOB |0 |UNDEF |__tha_read_w_pc_frame  | 0| 0|NOTY |GLOB |0 |UNDEF |__tha_write_w_pc_frame
To use discover, the input binary must be compiled with one of the compiler optimization flags (-xO1, -xO2, -xO3, -xO4, -xO5). The compiler must be from a release no earlier than Oracle Solaris Studio 12 Update 1. The operating system must be at least Oracle Solaris 10 Update 5 or OpenSolaris version snv_70. Otherwise, you may get a warning as shown here.
% discover -i datarace -o a.out.i a.out discover (warning): a.out has no annotations. Results may be incomplete. See discover documentation for compiler flag/OS recommendation
You might also be able to use the discover tool on an earlier Solaris version running on a SPARC-based system if the binary was compiled with the compiler option -xbinopt=prepare. See the cc(1), CC(1), or f95(1) man pages for information about this compiler option.