名前空間
変種
操作

std::atomic::compare_exchange_weak, std::atomic::compare_exchange_strong

提供: cppreference.com
< cpp‎ | atomic‎ | atomic

 
 
アトミック操作ライブラリ
タイプ
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
atomic(C++11)
atomic_is_lock_free(C++11)
機能します
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
atomic_store
atomic_store_explicit
(C++11)
(C++11)
atomic_load
atomic_load_explicit
(C++11)
(C++11)
atomic_exchange
atomic_exchange_explicit
(C++11)
(C++11)
atomic_compare_exchange_weak
atomic_compare_exchange_weak_explicit
atomic_compare_exchange_strong
atomic_compare_exchange_strong_explicit
(C++11)
(C++11)
(C++11)
(C++11)
atomic_fetch_add
atomic_fetch_add_explicit
(C++11)
(C++11)
atomic_fetch_sub
atomic_fetch_sub_explicit
(C++11)
(C++11)
atomic_fetch_and
atomic_fetch_and_explicit
(C++11)
(C++11)
atomic_fetch_or
atomic_fetch_or_explicit
(C++11)
(C++11)
atomic_fetch_xor
atomic_fetch_xor_explicit
(C++11)
(C++11)
アトミックのフラグ
Original:
Atomic flags
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
atomic_flag(C++11)
atomic_flag_test_and_set
atomic_flag_test_and_set_explicit
(C++11)
(C++11)
atomic_flag_clear
atomic_flag_clear_explicit
(C++11)
(C++11)
初期化
Original:
Initialization
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
atomic_init(C++11)
ATOMIC_VAR_INIT(C++11)
ATOMIC_FLAG_INIT(C++11)
メモリは発注
Original:
Memory ordering
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
memory_order(C++11)
kill_dependency(C++11)
atomic_thread_fence(C++11)
atomic_signal_fence(C++11)
 
std::atomic
メンバ関数
Original:
Member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
atomic::atomic
atomic::operator=
atomic::is_lock_free
atomic::store
atomic::load
atomic::operator T
atomic::exchange
atomic::compare_exchange
特殊なメンバ関数
Original:
Specialized member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
atomic::fetch_add
atomic::fetch_sub
atomic::fetch_and
atomic::fetch_or
atomic::fetch_xor
atomic::operator++
atomic::operator++(int)
atomic::operator--
atomic::operator--(int)
atomic::operator+=
atomic::operator-=
atomic::operator&=
atomic::operator|=
atomic::operator^=
 
Defined in header <atomic>
bool compare_exchange_weak( T& expected, T desired,

                            std::memory_order success,
                            std::memory_order failure );

bool compare_exchange_weak( T& expected, T desired,
                            std::memory_order success,

                            std::memory_order failure ) volatile;
(1) (C + + 11以来)
bool compare_exchange_weak( T& expected, T desired,

                            std::memory_order order =
                                std::memory_order_seq_cst );

bool compare_exchange_weak( T& expected, T desired,
                            std::memory_order order =

                                std::memory_order_seq_cst ) volatile;
(2) (C + + 11以来)
bool compare_exchange_strong( T& expected, T desired,

                              std::memory_order success,
                              std::memory_order failure );

bool compare_exchange_strong( T& expected, T desired,
                              std::memory_order success,

                              std::memory_order failure ) volatile;
(3) (C + + 11以来)
bool compare_exchange_strong( T& expected, T desired,

                              std::memory_order order =
                                  std::memory_order_seq_cst );

bool compare_exchange_strong( T& expected, T desired,
                              std::memory_order order =

                                  std::memory_order_seq_cst ) volatile;
(4) (C + + 11以来)
アトミック*thisが指す値を持つexpectedに格納された値を比較し、それらが等しい場合、desired(リード·モディファイ·ライト操作を実行する)で前者に置き換えられます。そうでない場合、(ロード操作を実行します)*this*expectedに格納される実際の値をロードします.
Original:
Atomically compares the value stored in *this 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 stored in *this 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.
リードモディファイライトのメモリモデルとロード操作はsuccessfailureそれぞれです。 (2)と(4)バージョンorderがために使用されるの両方のリード·モディファイ·ライト、およびロード操作を除き、そのstd::memory_order_releasestd::memory_order_relaxedorder == std::memory_order_acq_rel場合、またはorder == std::memory_order_releaseそれぞれのロード操作に使用され.
Original:
The memory models for the read-modify-write and load operations are success and failure respectively. In the (2) and (4) versions order is used for both read-modify-write and load operations, except that std::memory_order_release and std::memory_order_relaxed are used for the load operation if order == std::memory_order_acq_rel, or order == std::memory_order_release respectively.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
機能の弱形(1-2)は、彼らが等しい場合でも、*this != *expectedかのように行動されている、見かけ上失敗が許可されている。比較交換がループになっている場合、弱いバージョンでは、いくつかのプラットフォーム上でより良いパフォーマンスを得ることができます。弱い比較交換はループが必要となり、強いものは強いものが好ましくないとすると.
Original:
The weak forms (1-2) of the functions are allowed to fail spuriously, that is, act as if *this != *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.

目次

[編集] パラメータ

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.
success -
比較が成功した場合にメモリの同期化は、リード·モディファイ·ライト操作の順序。すべての値が許可されています.
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.
failure -
比較が失敗した場合にメモリ同期は、ロード操作の順序。 std::memory_order_releaseまたはstd::memory_order_ack_relsuccessより強い順序を指定することはできませんすることはできません
Original:
the memory synchronization 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 success
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
order -
メモリの同期は両方の操作の順序
Original:
the memory synchronization ordering for both operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] 値を返します

true基礎アトミック値が変更された場合、falseその他のとき.
Original:
true if the underlying atomic value was changed, false otherwise.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] 例外

noexcept specification:  
noexcept
  (C + + 11以来)

[編集]

いずれかの変更をアトミック変数または比較のために使用される変数の値をcompare_exchange_strong方法を示しています.
Original:
Demonstrates how compare_exchange_strong either changes the value of the atomic variable or the variable used for comparison.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

#include <atomic>
#include <iostream>
 
std::atomic<int>  ai;
 
int  tst_val= 4;
int  new_val= 5;
bool exchanged= false;
 
void valsout()
{
    std::cout << "ai= " << ai
	      << "  tst_val= " << tst_val
	      << "  new_val= " << new_val
	      << "  exchanged= " << std::boolalpha << exchanged
	      << "\n";
}
 
int main()
{
    ai= 3;
    valsout();
 
    // tst_val != ai   ==>  tst_val is modified
    exchanged= ai.compare_exchange_strong( tst_val, new_val );
    valsout();
 
    // tst_val == ai   ==>  ai is modified
    exchanged= ai.compare_exchange_strong( tst_val, new_val );
    valsout();
 
    return 0;
}

Output:

ai= 3  tst_val= 4  new_val= 5  exchanged= false
ai= 3  tst_val= 3  new_val= 5  exchanged= false
ai= 5  tst_val= 3  new_val= 5  exchanged= true

[編集] も参照してください

アトミックに非アトミック引数でアトミックオブジェクトの値を比較し、等しいか、またはアトミックロードする場合しない場合、原子交換を行う
Original:
atomically compares the value of the atomic object with non-atomic argument and performs atomic exchange if equal or atomic load if not
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(関数テンプレート) [edit]