atomic_compare_exchange_weak, atomic_compare_exchange_strong, atomic_compare_exchange_weak_explicit, atomic_compare_exchange_strong_explicit
来自cppreference.com
|
|
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
| 在头文件 <stdatomic.h> 中定义
|
||
| _Bool atomic_compare_exchange_strong( volatile A* obj, C* expected, C desired ); |
(1) | |
| _Bool atomic_compare_exchange_weak( volatile A *obj, C* expected, C desired ); |
(2) | |
| _Bool atomic_compare_exchange_strong_explicit( volatile A* obj, C* expected, C desired, |
(3) | |
| _Bool atomic_compare_exchange_weak_explicit( volatile A *obj, C* expected, C desired, |
(4) | |
原子的值进行比较,指出,
obj指出,expected的价值,如果这些都是平等的,取代了以前的desired(执行读 - 修改 - 写操作)。否则,加载的实际值所指向的obj到*expected(执行负载操作).原文:
Atomically compares the value pointed to by
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)版本默认情况下,使用memory_order_seq_cst.原文:
The memory models for the read-modify-write and load operations are
succ and fail respectively. The (1-2) versions use memory_order_seq_cst by default.的弱形式((1)和(3))的功能允许意外失败,即,如果*obj != *expected作为即使它们是相等的。当比较和交换是在一个循环中,弱版本会带来更好的性能,在某些平台上。当一个弱的比较和交换,需要一个循环,一个强大的,强大的一个是最好的.
原文:
The weak forms ((1) and (3)) of the functions are allowed to fail spuriously, that is, act as if *obj != *expected even if they are equal. When a compare-and-exchange is in a loop, the weak version will yield better performance on some platforms. When a weak compare-and-exchange would require a loop and a strong one would not, the strong one is preferable.
这是一个通用函数定义的所有原子的对象类型。
A是一个原子对象的类型,C非原子的类型,对应于A.原文:
This is a 通用函数 defined for all atomic object types.
A is the type of an atomic object, C is the non-atomic type corresponding to A.[编辑] 参数
| 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 | - | 内存同步的读 - 修改 - 写操作的顺序,如果比较成功。允许所有的值都.
原文: the memory synchronization ordering for the read-modify-write operation if the comparison succeeds. All values are permitted. |
| fail | - | 存储器同步的负载操作的顺序,如果比较失败。不能是memory_order_release或memory_order_ack_rel并且不能指定更强的顺序比
succ原文: the memory synchronization ordering for the load operation if the comparison fails. Cannot be memory_order_release or memory_order_ack_rel and cannot specify stronger ordering than succ |
[编辑] 返回值
的比较结果:true如果
*obj等于*exp,false否则.原文:
The result of the comparison: true if
*obj was equal to *exp, false otherwise.[编辑] 另请参阅
| 交换值与原子的对象的值 原文: swaps a value with the value of an atomic object (函数) | |
| C++ documentation for atomic_compare_exchange_weak, atomic_compare_exchange_strong, atomic_compare_exchange_weak_explicit, atomic_compare_exchange_strong_explicit
| |