std::kill_dependency
来自 cppreference.cn
< 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
|