Synchronization Primitives

The synchronization primitive intrinsics provide a variety of operations. Besides performing these operations, each intrinsic has two key properties:

For the intrinsics listed below, <type> is either a 32-bit or 64-bit integer.

Atomic Fetch-and-op Operations

<type> __sync_fetch_and_add(<type> *ptr,<type> val)
<type> __sync_fetch_and_and(<type> *ptr,<type> val)
<type> __sync_fetch_and_nand(<type> *ptr,<type> val)
<type> __sync_fetch_and_or(<type> *ptr,<type> val)
<type> __sync_fetch_and_sub(<type> *ptr,<type> val)
<type> __sync_fetch_and_xor(<type> *ptr,<type> val)

Atomic Op-and-fetch Operations

<type> __sync_add_and_fetch(<type> *ptr,<type> val)
<type> __sync_sub_and_fetch(<type> *ptr,<type> val)
<type> __sync_or_and_fetch(<type> *ptr,<type> val)
<type> __sync_and_and_fetch(<type> *ptr,<type> val)
<type> __sync_nand_and_fetch(<type> *ptr,<type> val)

<type> __sync_xor_and_fetch(<type> *ptr,<type> val)

Atomic Compare-and-swap Operations

<type> __sync_val_compare_and_swap(<type> *ptr, <type> old_val, <type> new_val)
int __sync_bool_compare_and_swap(<type> *ptr, <type> old_val, <type> new_val)

Atomic Synchronize Operation

void __sync_synchronize (void);

Atomic Lock-test-and-set Operation

<type> __sync_lock_test_and_set(<type> *ptr,<type> val)

Atomic Lock-release Operation

void __sync_lock_release(<type> *ptr)