名前空間
変種
操作

std::kill_dependency

From cppreference.com
< cpp‎ | atomic
 
 
並行性サポートライブラリ
スレッド
(C++11)
(C++20)
this_thread 名前空間
(C++11)
(C++11)
(C++11)
協調的なキャンセル
排他制御
(C++11)
汎用ロック管理
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
条件変数
(C++11)
セマフォ
ラッチとバリア
(C++20)
(C++20)
future
(C++11)
(C++11)
(C++11)
(C++11)
安全なメモリ解放 (Safe Reclamation)
(C++26)
ハザードポインタ
アトミック型
(C++11)
(C++20)
アトミック型の初期化
(C++11)(C++20で非推奨)
(C++11)(C++20で非推奨)
メモリオーダー
kill_dependency
(C++11)(C++26で非推奨)
アトミック操作のためのフリー関数
アトミックフラグのためのフリー関数
 
ヘッダー <atomic> で定義
template< class T >
T kill_dependency( T y ) noexcept;
(C++11以降)
(C++26 以降 constexpr)
(C++26で非推奨)

コンパイラに、std::memory_order_consume アトミックロード操作によって開始された依存関係ツリーが、std::kill_dependency の戻り値を超えて拡張しないことを通知します。つまり、引数は戻り値に依存関係を伝達しません。

これは、依存関係チェーンが関数スコープを離れる場合に、不要な std::memory_order_acquire フェンスを回避するために使用できます (関数に [[carries_dependency]] 属性がない場合)。

(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
}

[編集] 関連項目

与えられたアトミック操作に対するメモリ順序制約を定義する
(enum) [編集]
C のドキュメント (kill_dependency)
English 日本語 中文(简体) 中文(繁體)