atomic_load(), atomic_load_explicit()

Atomically read the value of an atomic object (C11)

Synopsis:

#include <stdatomic.h>

C atomic_load( volatile A *obj );

C atomic_load_explicit( volatile A *obj,
                        memory_order order );

Arguments:

obj
A pointer to the atomic object (see the atomic_* types) whose value you want to read.
order
(atomic_load_explicit() only) The memory_order to use for the operation. This must be memory_order_relaxed, memory_order_consume, memory_order_acquire, or memory_order_seq_cst.

Library:

Description:

The atomic_load() and atomic_load_explicit() functions are generic functions that atomically read the value of the given atomic object. The atomic_load() function orders memory access according to memory_order_seq_cst; atomic_load_explicit() orders them as specified by order.

The implementation of atomic functions may depend on the architecture. For more information, see LL/SC vs LSE atomic operations in the description in Building Embedded Systems of the cpuinfo area of the system page.

Returns:

The current value of the object. The “C” represents the non-atomic data type that corresponds to the atomic object.

Classification:

C11

Safety:  
Cancellation point No
Interrupt handler Read the Caveats
Signal handler Read the Caveats
Thread Yes

Caveats:

If this function is lock-free (see atomic_is_lock_free()), it's safe to call it from an ISR or signal handler.