名前空間
変種
操作

std::atomic_compare_exchange_weak, std::atomic_compare_exchange_strong, std::atomic_compare_exchange_weak_explicit, std::atomic_compare_exchange_strong_explicit

提供: cppreference.com
< cpp‎ | 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)
 
Defined in header <atomic>
template< class T >

bool atomic_compare_exchange_weak( std::atomic<T>* obj,
                                   T* expected, T desired );
template< class T >
bool atomic_compare_exchange_weak( volatile std::atomic<T>* obj,

                                   T* expected, T desired );
(1) (C++11およびそれ以降)
template< class T >

bool atomic_compare_exchange_strong( std::atomic<T>* obj,
                                     T* expected, T desired );
template< class T >
bool atomic_compare_exchange_strong( volatile std::atomic<T>* obj,

                                     T* expected, T desired );
(2) (C++11およびそれ以降)
template< class T >

bool atomic_compare_exchange_weak_explicit( std::atomic<T>* obj,
                                            T* expected, T desired,
                                            std::memory_order succ,
                                            std::memory_order fail );
template< class T >
bool atomic_compare_exchange_weak_explicit( volatile std::atomic<T>* obj,
                                            T* expected, T desired,
                                            std::memory_order succ,

                                            std::memory_order fail );
(3) (C++11およびそれ以降)
template< class T >

bool atomic_compare_exchange_strong_explicit( std::atomic<T>* obj,
                                              T* expected, T desired,
                                              std::memory_order succ,
                                              std::memory_order fail );
template< class T >
bool atomic_compare_exchange_strong_explicit( volatile std::atomic<T>* obj,
                                              T* expected, T desired,
                                              std::memory_order succ,

                                              std::memory_order fail );
(4) (C++11およびそれ以降)
アトミック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.
リードモディファイライトのメモリモデルとロード操作はsuccfailそれぞれです。 (1-2)のバージョンでは、デフォルトでstd::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 std::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.
機能の弱形((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.
これらの機能はstd::atomicのメンバ関数の用語で定義されています
Original:
These functions are defined in terms of member functions of std::atomic:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
1) obj->compare_exchange_weak(exp, desr)
2) obj->compare_exchange_strong(exp, desr)
3) obj->compare_exchange_weak(exp, desr, succ, fail)
4) obj->compare_exchange_strong(exp, desr, succ, fail)

目次

[編集] パラメータ

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 -
比較が成功した場合、メモリsycnhronizationは、読み出し - 変更 - 書き込み操作の順序。すべての値が許可されています.
Original:
the memory sycnhronization 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 -
比較に失敗した場合、メモリsycnhronizationは、ロード操作の順序。 std::memory_order_releaseまたはstd::memory_order_ack_relsuccより強い順序を指定することはできませんすることはできません
Original:
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
The 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.

[編集] 例外

noexcept specification:  
noexcept
  (C++11およびそれ以降)

[編集]

この例では、比較交換を単独でリンクされたリストにロックフリーappendを実装するために使用することができる方法を示しています
Original:
This example shows how compare-and-exchange may be used to implement lock-free append to a singly linked list
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

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));
}


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

アトミックに非アトミック引数でアトミックオブジェクトの値を比較し、等しいか、またはアトミックロードする場合しない場合、原子交換を行う
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.

(パブリックメンバ関数of std::atomic) [edit]
アトミックに非アトミック引数でアトミックオブジェクトの値を置き換え、原子の古い値を返します
Original:
atomically replaces the value of the atomic object with non-atomic argument and returns the old value of the atomic
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(関数テンプレート) [edit]
のstd :: shared_ptrのためのアトミック操作を専門としています
Original:
specializes atomic operations for std::shared_ptr
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, atomic_compare_exchange_explicit