Chapter 28. Concurrency

Table of Contents

Interface to Locks and Mutexes
Interface to Atomic Functions
Using Builtin Atomic Functions
Thread Abstraction

Two functions and one type form the base of atomic support.

The type _Atomic_word is a signed integral type supporting atomic operations.

The two functions functions are:

__exchange_and_add_dispatch(volatile _Atomic_word*, int);

__atomic_add_dispatch(volatile _Atomic_word*, int);

Both of these functions are declared in the header file <ext/atomicity.h>, and are in namespace __gnu_cxx.

These functions forward to one of several specialized helper functions, depending on the circumstances. For instance,


Calls through to either of:

However, only __exchange_and_add_dispatch and __atomic_add_dispatch should be used. These functions can be used in a portable manner, regardless of the specific environment. They are carefully designed to provide optimum efficiency and speed, abstracting out atomic accesses when they are not required (even on hosts that support compiler intrinsics for atomic operations.)

In addition, there are two macros



Which expand to the appropriate write and read barrier required by the host hardware and operating system.