Specifications

Red Hat Enterprise Linux to Oracle Solaris Porting Guide
56
developer to specify how. Within legacy code, execution loops, in particular, often represent
opportunities for optimization where previously repetitive serial operations can be divided into
multiple, independent execution threads. Several compiler flags are used with Oracle Solaris Studio
compilers to govern automatic parallelization behavior:
The -xautopar compiler flag tells the compiler to look for loops that can be safely parallelized in
the code.
The -xreduction compiler flag can be used to recognize and parallelize reduction operations that
take a range of values and output a single value, such as summing all the values in an array.
The -xloopinfo compiler flag can be specified to generate information about loops that the
compiler has parallelized.
Addressing Multithreaded Application Issues
Using Thread Analyzer
The Oracle Solaris Studio Thread Analyzer is an advanced tool for application optimization, and it is
designed to help ensure multithreaded application correctness. Specifically, the Thread Analyzer can
help detect, analyze, and debug the special situations that can arise in multithreaded applications.
Detecting Race Conditions and Deadlocks
Data races can cause incorrect or unpredictable results, and they can occur arbitrarily far way from
where a problem seems to occur. Data races occur under the following conditions:
Two or more threads in a single process concurrently access the same memory location.
At least one of the threads is accessing the memory location for writing.
The threads are not using any exclusive locks to control their accesses to that memory.
Deadlock conditions occur when one thread is blocked waiting on a resource held by a second thread,
while the second thread is blocked waiting on a resource held by the first (or an equivalent situation
with more threads involved).
To instrument the source code for the detection of data race and deadlock issues, the code is compiled
with a special flag, executed under control of the collect -r command, and then loaded into the
Thread Analyzer.
Applications are first compiled with the
-xinstrument=datarace compiler flag. It is recommended
that the
-g flag also be set and that no optimization level be used to help ensure that the line numbers
and call-stacks information are returned correctly.
The resulting application code is then executed within the
collect -r command, allowing for the
collection of key runtime information. Use the
collect –r all option to run the program and
create a data race detection and deadlock detection experiment during the execution of the process.