I am looking for some atomic_set
-like function that sets the variable's value atomically and, at the same time, it returns the previous value similar to the compare_and_swap
.
Here is what I expect:
int old_val = atomic_set(mem_address, 10);
The C11 <stdatomic.h>
defines atomic_exchange()
and atomic_exchange_explicit()
that perform this operation.
The atomic_exchange_explicit()
form allows you to specify the memory ordering required (the plain atomic_exchange()
uses the strongest memory ordering memory_order_seq_cst
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With