Updated: April 19, 2023 |
Atomically change the value of an atomic object (C11)
#include <stdatomic.h> C atomic_exchange( volatile A *obj, C desired ); C atomic_exchange_explicit( volatile A *obj, C desired, memory_order order );
The atomic_exchange() and atomic_exchange_explicit() functions are generic functions that atomically change the value of the given atomic object. The atomic_exchange() function orders memory access according to memory_order_seq_cst; atomic_exchange_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.
The value of the object before the operation.
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | Read the Caveats |
Signal handler | Read the Caveats |
Thread | Yes |
If this function is lock-free (see atomic_is_lock_free()), it's safe to call it from an ISR or signal handler.