JavaScript is required to for searching.
Skip Navigation Links
Exit Print View
Oracle Solaris Studio 12.3: C User's Guide     Oracle Solaris Studio 12.3 Information Library
search filter icon
search icon

Document Information


1.  Introduction to the C Compiler

2.  C-Compiler Implementation-Specific Information

3.  Parallelizing C Code

3.1 Overview of Parallelization

3.2 Parallelizing for OpenMP

3.2.1 Handling OpenMP Runtime Warnings

3.2.2 Environment Variables

3.2.3 Using restrict in Parallel Code

3.3 Data Dependence and Interference

3.3.1 Parallel Execution Model

3.3.2 Private Scalars and Private Arrays

3.3.3 Storeback

3.3.4 Reduction Variables

3.4 Speedups

3.4.1 Amdahl's Law Overheads Gustafson's Law

3.5 Load Balance and Loop Scheduling

3.5.1 Static or Chunk Scheduling

3.5.2 Self-Scheduling

3.5.3 Guided Self-Scheduling

3.6 Loop Transformations

3.6.1 Loop Distribution

3.6.2 Loop Fusion

3.6.3 Loop Interchange

3.7 Aliasing and Parallelization

3.7.1 Array and Pointer References

3.7.2 Restricted Pointers

3.8 Memory-Barrier Intrinsics

4.  lint Source Code Checker

5.  Type-Based Alias Analysis

6.  Transitioning to ISO C

7.  Converting Applications for a 64-Bit Environment

8.  cscope: Interactively Examining a C Program

A.  Compiler Options Grouped by Functionality

B.  C Compiler Options Reference

C.  Implementation-Defined ISO/IEC C99 Behavior

D.  Features of C99

E.  Implementation-Defined ISO/IEC C90 Behavior

F.  ISO C Data Representations

G.  Performance Tuning

H.  Oracle Solaris Studio C: Differences Between K&R C and ISO C


3.8 Memory-Barrier Intrinsics

The compiler provides the header file mbarrier.h, which defines various memory-barrier intrinsics for SPARC and x86 processors. These intrinsics may be of use to developers writing multithreaded code using their own synchronization primitives. Refer to the documentation of their processors to determine when and whether these intrinsics are necessary for their particular situation.

Memory-ordering intrinsics supported by mbarrier.h are:

All the barrier intrinsics except the __compiler_barrier() intrinsic generate memory-ordering instructions. On x86 platforms, these are mfence, sfence, or lfence instructions. On SPARC platforms, these are membar instructions.

The __compiler_barrier() intrinsic generates no instructions and instead informs the compiler that all previous memory operations must be completed before any future memory operations are initiated. The practical result is that all non-local variables and local variables with the static storage class specifier will be stored back to memory before the barrier, and reloaded after the barrier. The compiler will not mix memory operations from before the barrier with those after. All other barriers implicitly include the behavior of the __compiler_barrier() intrinsic.

In the following example, the presence of the __compiler_barrier() intrinsic stops the compiler from merging the two loops:

#include "mbarrier.h"
int thread_start[16];
void start_work()
/* Start all threads */
   for (int i=0; i<8; i++)
/* Wait for all threads to complete */
   for (int i=0; i<8; i++)
      while (thread_start[i]==1){}