是否有任何原子集操作 returns C 中的旧值?
Is there any atomic set operation that returns the old value in C?
我正在寻找一些类似于 atomic_set
的函数,它以原子方式设置变量的值,同时,它 returns 类似于 compare_and_swap
的先前值。
这是我的预期:
int old_val = atomic_set(mem_address, 10);
C11<stdatomic.h>
定义了执行这个操作的atomic_exchange()
和atomic_exchange_explicit()
。
atomic_exchange_explicit()
形式允许您指定所需的内存顺序(普通 atomic_exchange()
使用最强的内存顺序 memory_order_seq_cst
)。
我正在寻找一些类似于 atomic_set
的函数,它以原子方式设置变量的值,同时,它 returns 类似于 compare_and_swap
的先前值。
这是我的预期:
int old_val = atomic_set(mem_address, 10);
C11<stdatomic.h>
定义了执行这个操作的atomic_exchange()
和atomic_exchange_explicit()
。
atomic_exchange_explicit()
形式允许您指定所需的内存顺序(普通 atomic_exchange()
使用最强的内存顺序 memory_order_seq_cst
)。