std::atomic_compare_exchange_weak, std::atomic_compare_exchange_strong, std::atomic_compare_exchange_weak_explicit, std::atomic_compare_exchange_strong_explicit
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <atomic> 中定义
|
||
template< class T > bool atomic_compare_exchange_weak( std::atomic<T>* obj, |
(1) | (C++11 起) |
template< class T > bool atomic_compare_exchange_strong( std::atomic<T>* obj, |
(2) | (C++11 起) |
template< class T > bool atomic_compare_exchange_weak_explicit( std::atomic<T>* obj, |
(3) | (C++11 起) |
template< class T > bool atomic_compare_exchange_strong_explicit( std::atomic<T>* obj, |
(4) | (C++11 起) |
obj
指出,expected
的价值,如果这些都是平等的,取代了以前的desired
(执行读 - 修改 - 写操作)。否则,加载的实际值所指向的obj
到*expected
(执行负载操作).obj
with the value pointed to by expected
, and if those are equal, replaces the former with desired
(performs read-modify-write operation). Otherwise, loads the actual value pointed to by obj
into *expected
(performs load operation).succ
和fail
。 (1-2)版本默认情况下,使用std::memory_order_seq_cst.succ
and fail
respectively. The (1-2) versions use std::memory_order_seq_cst by default.目录 |
[编辑] 参数
obj | - | 指针的原子对象测试和修改
原文: pointer to the atomic object to test and modify |
expected | - | 预期发现的原子对象中的值的指针
原文: pointer to the value expected to be found in the atomic object |
desired | - | 要存储的值的原子对象中,如果是如预期的那样
原文: the value to store in the atomic object if it is as expected |
succ | - | 内存sycnhronization的读 - 修改 - 写操作的顺序,如果比较成功。允许所有的值都.
原文: the memory sycnhronization ordering for the read-modify-write operation if the comparison succeeds. All values are permitted. |
fail | - | 存储器sycnhronization订货的负载操作,如果比较失败。不能是std::memory_order_release或std::memory_order_ack_rel并且不能指定更强的顺序比
succ 原文: the memory sycnhronization ordering for the load operation if the comparison fails. Cannot be std::memory_order_release or std::memory_order_ack_rel and cannot specify stronger ordering than succ |
[编辑] 返回值
*obj
等于*exp
,false否则.*obj
was equal to *exp
, false otherwise.[编辑] 例外
[编辑] 示例
void append(list* s, node* n) { node* head; do { head = s->head; n->next = head; } while(! std::atomic_compare_exchange_weak(s->head, head, n)); }
[编辑] 另请参阅
原子原子对象与非原子的参数的值的比较,并执行原子交换,如果等于或原子的负载如果不是 原文: atomically compares the value of the atomic object with non-atomic argument and performs atomic exchange if equal or atomic load if not (公共成员函数of std::atomic )
| |
(C++11) (C++11) |
以原子的原子对象非原子参数的值替换,并返回旧值的原子 原文: atomically replaces the value of the atomic object with non-atomic argument and returns the old value of the atomic (函数模板) |
专业的std :: shared_ptr的原子操作 原文: specializes atomic operations for std::shared_ptr (函数模板) | |
C documentation for atomic_compare_exchange, atomic_compare_exchange_explicit
|