名前空間
変種
操作

memory_order

提供: cppreference.com
< c‎ | atomic

Defined in header <stdatomic.h>
enum memory_order {

    memory_order_relaxed,
    memory_order_consume,
    memory_order_acquire,
    memory_order_release,
    memory_order_acq_rel,
    memory_order_seq_cst

};
(C11以来)
memory_order非アトミックなメモリアクセスはアトミック操作周りに注文する方法を指定します。これの根拠は、同時にマルチコアシステム上のいくつかの変数に読み取りおよび書き込みする際には、いくつかのスレッドが、あるスレッドがを参照してくださいかもしれないということです、別のスレッドがそれを書いているものとは異なる順序で値が変化します。また、変更の見かけの順序はいくつかのリーダー·スレッド間で異なる場合があります。メモリはアトミック変数へのアクセスはすべてが連続していることを保証することは、いくつかのケースでパフォーマンスを傷つけることがあります。 std::memory_orderコンパイラが強制しなければならない正確な制約を指定することができます.
Original:
memory_order specifies how non-atomic memory accesses are to be ordered around an atomic operation. The rationale of this is that when several threads simultaneously read and write to several variables on multi-core systems, one thread might see the values change in different order than another thread has written them. Also, the apparent order of changes may be different across several reader threads. Ensuring that all memory accesses to atomic variables are sequential may hurt performance in some cases. std::memory_order allows to specify the exact constraints that the compiler must enforce.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
これは、追加のパラメータを使用して、ライブラリー内の各アトミックな操作でカスタムメモリの順序を指定することが可能です。デフォルトはstd::memory_order_seq_cstです.
Original:
It's possible to specify custom memory order for each atomic operation in the library via an additional parameter. The default is std::memory_order_seq_cst.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

目次

[編集] 定数

Defined in header <atomic>
Original:
Value
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Explanation
memory_order_relaxed
'リラックス'は順序:アトミック変数の周りにメモリアクセスの順序変更には制約はありません.
Original:
Relaxed ordering: there are no constraints on reordering of memory accesses around the atomic variable.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
memory_order_consume
操作 '消費しません':しない、現在ロードされている値に依存し、このロードの前に並べ替えることができ、現在のスレッドで読み込みます。これは、現在のスレッドに表示されている同じアトミック変数を解放し、他のスレッドでの従属変数への書き込みが保証されます。ほとんどのプラットフォームでは、これが唯一のコンパイラの最適化に影響を及ぼし.
Original:
Consume operation: no reads in the current thread dependent on the value currently loaded can be reordered before this load. This ensures that writes to dependent variables in other threads that release the same atomic variable are visible in the current thread. On most platforms, this affects compiler optimization only.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
memory_order_acquire
操作 '取得しない':しない、現在のスレッドを読み込んで、この負荷の前に並べ替えることができます。これは、すべてが同じアトミック変数を解放し、他のスレッドで書き込みが現在のスレッドに表示されていることを保証.
Original:
Acquire operation: no reads in the current thread can be reordered before this load. This ensures that all writes in other threads that release the same atomic variable are visible in the current thread.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
memory_order_release
'リリース'操作:現在のスレッドに書いてありませんが、この店の後に並べ替えることができます。これは、現在のスレッドに書いてすべてが同じアトミック変数を取得し、他のスレッドに表示されていることを保証.
Original:
Release operation: no writes in the current thread can be reordered after this store. This ensures that all writes in the current thread are visible in other threads that acquire the same atomic variable.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
memory_order_acq_rel
'取得放'操作:現在のスレッドを読み込んでないが同様、現在のスレッドに書いてないように、この負荷の前に並べ替えることができますこのストアの後に並べ替えることができます。操作は、リード·モディファイ·ライト操作です。これは、修正や変更が同じアトミック変数を取得し、他のスレッドに表示される前に、すべてが同じアトミック変数を解放し、別のスレッドで書き込みが表示されていることを保証されてい.
Original:
Acquire-release operation: no reads in the current thread can be reordered before this load as well as no writes in the current thread can be reordered after this store. The operation is read-modify-write operation. It is ensured that all writes in another threads that release the same atomic variable are visible before the modification and the modification is visible in other threads that acquire the same atomic variable.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
memory_order_seq_cst
'シーケンシャル順序'。操作は習得リリース操作と同じ意味を持っており、さらに連続的に一貫性のある操作の順序を持​​っている.
Original:
Sequential ordering. The operation has the same semantics as acquire-release operation, and additionally has sequentially-consistent operation 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_relaxed以下の特性を示す
Original:
Atomic operations tagged memory_order_relaxed exhibit the following properties:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • 他のメモリアクセスの順序付けは、一切保証されていません。これは、アトミック変数を使用して複数のスレッドを同期することは不可能であることを意味します.
    Original:
    No ordering of other memory accesses is ensured whatsoever. This means that it is not possible to synchronize several threads using the atomic variable.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 読み込み、それ自体が順序付けられているアトミック変数に書き込みます。スレッドが同じオブジェクトから同じスレッドによって値、後続の読み取りを読み取ると、以前の値を生成することはできません.
    Original:
    Reads and writes to the atomic variable itself are ordered. Once a thread reads a value, a subsequent read by the same thread from the same object can not yield an earlier value.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
たとえば、xy当初はゼロ
Original:
For example, with x and y initially zero,
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

// Thread 1:
r1 = atomic_load_explicit(y, memory_order_relaxed);
atomic_store_explicit(x, r1, memory_order_relaxed);
// Thread 2:
r2 = atomic_load_explicit(x, memory_order_relaxed);
atomic_store_explicit(y, 42, memory_order_relaxed);

r1 == r2 == 42を生成するために許可されている.
Original:
is allowed to produce r1 == r2 == 42.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] 発注リリース - 消費する

アトミックストアがタグ付きの場合memory_order_releaseと同じ変数から原子負荷がmemory_order_consumeタグ付けされて、操作には、以下の特性を示す
Original:
If an atomic store is tagged memory_order_release and an atomic load from the same variable is tagged memory_order_consume, the operations exhibit the following properties:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • いいえアトミックストアの後で並べ替えることができるライタスレッドに書いてありません
    Original:
    No writes in the writer thread can be reordered after the atomic store
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 読み取りまたはアトミック負荷から受け取った値に依存して書き込むんは、アトミックロードの前に並べ替えることはできません。アドレスまたは値をアトミック変数の値から計算されることを意味する "に依存"。スレッド間の同期のこの形式は、 "依存関係の順序"として知られています.
    Original:
    No reads or writes dependent on the value received from atomic load can be reordered before the atomic load. "Dependent on" means that the address or value is computed from the value of the atomic variable. This form of synchronization between threads is known as "dependency ordering".
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 同期は、スレッドと''かかる同じアトミック変数を解放するとの間に確立される。他のスレッドが同期化されたスレッドのいずれかまたは両方を比べてメモリアクセスの異なる順序を確認することができます.
    Original:
    The synchronization is established only between the threads releasing and consuming the same atomic variable. Other threads can see different order of memory accesses than either or both of the synchronized threads.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 同期が推移的である。我々は次のような状況を持っているなら、それは、次のとおりです
    Original:
    The synchronization is transitive. That is, if we have the following situation:
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • スレッド'は、アトミック変数を解放 A.
    Original:
    Thread A releases atomic variable a.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • スレッド Bアトミック変数を消費 A.
    Original:
    Thread B consumes atomic variable a.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • アトミック変数 Bに依存しているA.
    Original:
    Atomic variable b is dependent on a.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • スレッド Bリリースアトミック変数 B.
    Original:
    Thread B releases atomic variable b.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • スレッド Cアトミック変数を消費または取得 B.
    Original:
    Thread C consumes or acquires atomic variable b.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
その後だけでなく、、A B B Cを同期していますが、、A Cも。つまり、すべてのスレッドによって書き込みのリリース前に発売されました Aを完了することが保証されているスレッドは、一度 Cに店舗を観察 B.
Original:
Then not only A and B or B and C are synchronized, but A and C also. That is, all writes by the thread A that were launched before the release of a are guaranteed to be completed once thread C observes the store to b.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
DEC Alphaの以外のすべての主流のCPU上で、依存関係の順序付けは自動的に行われ、追加のCPUの命令は、特定のコンパイラの最適化が影響を受けるため、この同期モードのために発行されていない(コンパイラをEGに関与しているオブジェクトに対する投機的なロードを実行することは禁止されてい依存関係の連鎖)
Original:
On all mainstream CPUs, other than DEC Alpha, dependency ordering is automatic, no additional CPU instructions are issued for this synchronization mode, only certain compiler optimizations are affected (e.g. the compiler is prohibited from performing speculative loads on the objects that are involved in the dependency chain)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] シーケンスを放します

いくつかの原子がある場合はストアがリリースされた、いくつかの他のスレッドがその原子上の読み出し - 変更 - 書き込み操作を実行し、 "解除シーケンス"が形成される:同じ、最初のスレッドと同期アトミックとに読み出し - 変更 - 書き込みを行うすべてのスレッドお互い彼らはmemory_order_releaseセマンティクスを持っていない場合でも。個々の消費者のスレッド間で不必要な同期をかけることなく、可能性のある複数の消費者の状況.. - これは、単一の生産者を作る
Original:
If some atomic is store-released and several other threads perform read-modify-write operations on that atomic, a "release sequence" is formed: all threads that perform the read-modify-writes to the same atomic synchronize with the first thread and each other even if they have no memory_order_release semantics. This makes single producer - multiple consumers situations possible without imposing unnecessary synchronization between individual consumer threads.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] リリース取得順序

アトミックストアがタグ付きの場合memory_order_releaseと同じ変数から原子負荷がmemory_order_acquireタグ付けされて、操作には、以下の特性を示す
Original:
If an atomic store is tagged memory_order_release and an atomic load from the same variable is tagged memory_order_acquire, the operations exhibit the following properties:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • いいえアトミックストアの後で並べ替えることができるライタスレッドに書いてありません
    Original:
    No writes in the writer thread can be reordered after the atomic store
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • リーダースレッドで読み込みなしは、アトミックロードの前に並べ替えることができません.
    Original:
    No reads in the reader thread can be reordered before the atomic load.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 同期は、をリリースすると''は同じアトミック変数を取得するスレッド間で確立されます。他のスレッドが同期化されたスレッドのいずれかまたは両方を比べてメモリアクセスの異なる順序を確認することができます.
    Original:
    The synchronization is established only between the threads releasing and acquiring the same atomic variable. Other threads can see different order of memory accesses than either or both of the synchronized threads.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 同期が推移的である。我々は次のような状況を持っているなら、それは、次のとおりです
    Original:
    The synchronization is transitive. That is, if we have the following situation:
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • スレッド'は、アトミック変数を解放 A.
    Original:
    Thread A releases atomic variable a.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • スレッド Bアトミック変数を消費 A.
    Original:
    Thread B consumes atomic variable a.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • スレッド Bリリースアトミック変数 B.
    Original:
    Thread B releases atomic variable b.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • スレッド Cアトミック変数を消費または取得 B.
    Original:
    Thread C consumes or acquires atomic variable b.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
その後だけでなく、、A B B Cを同期していますが、、A Cも。つまり、すべてのスレッドによって書き込みのリリース前に発売されました Aを完了することが保証されているスレッドは、一度 Cに店舗を観察 B.
Original:
Then not only A and B or B and C are synchronized, but A and C also. That is, all writes by the thread A that were launched before the release of a are guaranteed to be completed once thread C observes the store to b.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
強く順序付けられたシステム(x86、SPARC、IBMメインフレーム)で、リリース取得順序は自動的に行われます。追加のCPUの命令は、特定のコンパイラの最適化(例えば、コンパイラがアトミックストアrelase過ぎ非アトミックストアを移動することを禁止またはそれ以前のロード取得アトミックより非アトミックロードを実行されている)が影響を受け、この同期モードのために発行されていません
Original:
On strongly-ordered systems (x86, SPARC, IBM mainframe), release-acquire ordering is automatic. No additional CPU instructions are issued for this synchronization mode, only certain compiler optimizations are affected (e.g. the compiler is prohibited from moving non-atomic stores past the atomic store-relase or perform non-atomic loads earlier than the atomic load-acquire)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] 連続して一貫性のある順序

アトミックストアとタグ付けされてmemory_order_seq_cstと同じ変数から原子負荷がmemory_order_seq_cstタグ付けされている場合は、動作は次のような特性を示す
Original:
If an atomic store and an is tagged memory_order_seq_cst and an atomic load from the same variable is tagged memory_order_seq_cst, then the operations exhibit the following properties:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • いいえアトミックストアの後で並べ替えることができるライタスレッドに書いてありません
    Original:
    No writes in the writer thread can be reordered after the atomic store
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • リーダースレッドで読み込みなしは、アトミックロードの前に並べ替えることができません.
    Original:
    No reads in the reader thread can be reordered before the atomic load.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 同期はstd::memory_order_seq_cstタグ付けされたすべてのアトミックな操作との間に確立される。このような原子操作を使用して、すべてのスレッドは、メモリアクセスの順序と同じ順序を参照してください。.
    Original:
    The synchronization is established between all atomic operations tagged std::memory_order_seq_cst. All threads using such atomic operation see the same order of memory accesses.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
シーケンシャルな順序は、すべての消費者が同じ順序で発生するすべての生産者の行動を観察しなければならない多くの複数のプロデューサ - 複数のコンシューマ場合にも必要です.
Original:
Sequential ordering is necessary for many multiple producer-multiple consumer situations where all consumers must observe the actions of all producers occurring in the same order.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
合計シーケンシャルな順序は、すべてのマルチコアシステム上でフルメモリフェンスCPUの命令を必要とします。それはすべてのメモリはすべてのスレッドに伝播するために強制的にアクセスするので、これはパフォーマンスのボトルネックになるかもしれ.
Original:
Total sequential ordering requires a full memory fence CPU instruction on all multi-core systems. This may become a performance bottleneck since it forces all memory accesses to propagate to every thread.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] 揮発性との関係

{{{1}}}
Original:
{{{2}}}
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集]