std::kill_dependency
From cppreference.com
| ヘッダー <atomic> で定義 |
||
template< class T > T kill_dependency( T y ) noexcept; |
(C++11以降) (C++26 以降 constexpr) (C++26で非推奨) |
|
|
コンパイラに、std::memory_order_consume アトミックロード操作によって開始された依存関係ツリーが、 これは、依存関係チェーンが関数スコープを離れる場合に、不要な std::memory_order_acquire フェンスを回避するために使用できます (関数に |
(C++26まで) |
|
単に y を返します。この関数テンプレートは非推奨です。 |
(C++26以降) |
目次 |
[編集] パラメータ
| y | - | 依存関係ツリーから戻り値を削除する式 |
[編集] 戻り値
y を返します。依存関係ツリーの一部ではなくなります(C++26まで)。
[編集] 例
[編集] file1.cpp:
struct Foo { int* a; int* b; }; std::atomic<Foo*> foo_head[10]; int foo_array[10][10]; // consume operation starts a dependency chain, which escapes this function [[carries_dependency]] Foo* f(int i) { return foo_head[i].load(memory_order_consume); } // the dependency chain enters this function through the right parameter and is // killed before the function ends (so no extra acquire operation takes place) int g(int* x, int* y [[carries_dependency]]) { return std::kill_dependency(foo_array[*x][*y]); }
[編集] file2.cpp:
[[carries_dependency]] struct Foo* f(int i); int g(int* x, int* y [[carries_dependency]]); int c = 3; void h(int i) { Foo* p; p = f(i); // dependency chain started inside f continues into p without undue acquire do_something_with(g(&c, p->a)); // p->b is not brought in from the cache do_something_with(g(p->a, &c)); // left argument does not have the carries_dependency // attribute: memory acquire fence may be issued // p->b becomes visible before g() is entered }
[編集] 関連項目
| (C++11) |
与えられたアトミック操作に対するメモリ順序制約を定義する (enum) |
| C のドキュメント (kill_dependency)
| |