std::kill_dependency
來自 cppreference.com
< cpp | 原子操作 (atomic)
定義於標頭檔案 <atomic> |
||
template< class T > T kill_dependency( T y ) noexcept; |
(C++11 起) (C++26 起為 constexpr) (C++26 中已棄用) |
|
通知編譯器,由 std::memory_order_consume 原子載入操作啟動的依賴樹不會超出 當依賴鏈離開函式作用域時(並且該函式沒有 |
(直到 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++11) |
定義給定原子操作的記憶體排序約束 (列舉) |
C 文件 關於 kill_dependency
|