atomic_compare_exchange_weak, atomic_compare_exchange_strong, atomic_compare_exchange_weak_explicit, atomic_compare_exchange_strong_explicit
来自cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
| Defined in header <stdatomic.h>
|
||
| _Bool atomic_compare_exchange_strong( volatile A* obj, C* expected, C desired ); |
(1) | (C11 起) |
| _Bool atomic_compare_exchange_weak( volatile A *obj, C* expected, C desired ); |
(2) | (C11 起) |
| _Bool atomic_compare_exchange_strong_explicit( volatile A* obj, C* expected, C desired, |
(3) | (C11 起) |
| _Bool atomic_compare_exchange_weak_explicit( volatile A *obj, C* expected, C desired, |
(4) | (C11 起) |
原子的值进行比较,指出,
obj指出,expected的价值,如果这些都是平等的,取代了以前的desired(执行读 - 修改 - 写操作)。否则,加载的实际值所指向的obj到*expected(执行负载操作).Original:
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).The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
内存模型的读 - 修改 - 写和加载操作
succ和fail。 (1-2)版本默认情况下,使用memory_order_seq_cst.Original:
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.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
的弱形式((1)和(3))的功能允许意外失败,即,如果*obj != *expected作为即使它们是相等的。当比较和交换是在一个循环中,弱版本会带来更好的性能,在某些平台上。当一个弱的比较和交换,需要一个循环,一个强大的,强大的一个是最好的.
Original:
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.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
这是一个通用函数定义的所有原子的对象类型。
A是一个原子对象的类型,C非原子的类型,对应于A.Original:
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.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[编辑] 参数
| obj | - | 指针的原子对象测试和修改
Original: pointer to the atomic object to test and modify The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| expected | - | 预期发现的原子对象中的值的指针
Original: pointer to the value expected to be found in the atomic object The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| desired | - | 要存储的值的原子对象中,如果是如预期的那样
Original: the value to store in the atomic object if it is as expected The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| succ | - | 内存同步的读 - 修改 - 写操作的顺序,如果比较成功。允许所有的值都.
Original: the memory synchronization ordering for the read-modify-write operation if the comparison succeeds. All values are permitted. The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| fail | - | 存储器同步的负载操作的顺序,如果比较失败。不能是memory_order_release或memory_order_ack_rel并且不能指定更强的顺序比
succOriginal: 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 succThe text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
[编辑] 返回值
的比较结果:true如果
*obj等于*exp,false否则.Original:
The result of the comparison: true if
*obj was equal to *exp, false otherwise.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[编辑] 另请参阅
| 交换值与原子的对象的值 Original: swaps a value with the value of an atomic object The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (函数) | |
| C++ documentation for atomic_compare_exchange_weak, atomic_compare_exchange_strong, atomic_compare_exchange_weak_explicit, atomic_compare_exchange_strong_explicit
| |