名稱空間
變體
操作

std::kill_dependency

來自 cppreference.com
 
 
併發支援庫
執行緒
(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)
期值
(C++11)
(C++11)
(C++11)
(C++11)
安全回收
(C++26)
危險指標
原子型別
(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 的返回值;也就是說,該引數不會將依賴關係帶入返回值。

當依賴鏈離開函式作用域時(並且該函式沒有 [[carries_dependency]] 屬性),這可用於避免不必要的 std::memory_order_acquire 屏障。

(直到 C++26)

簡單地返回 y。此函式模板已棄用。

(C++26 起)

目錄

[編輯] 引數

y - 要從依賴樹中移除其返回值的表示式。

[編輯] 返回值

返回 y,不再是依賴樹的一部分(直到 C++26)

[編輯] 示例

[編輯] 檔案1.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]);
}
[編輯] 檔案2.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 文件 關於 kill_dependency