在线文档教程
C++

std::kill_dependency

STD:杀死[医]依赖性

Defined in header
template< class T > T kill_dependency( T y (since C++11)

通知编译器,依赖树由std::memory_order_consume原子加载操作不会扩展到std::kill_dependency也就是说,该参数不将依赖项携带到返回值中。

这可能是用来避免不必要的。std::memory_order_acquire当依赖链离开函数作用域%28且函数没有[[载运[医][受抚养人]]属性%29。

参数

y-the expression whose return value is to be removed from a dependency tree

返回值

回报y不再是依赖树的一部分。

例外

noexcept规格:

noexcept

实例

二次

//file1.cpp struct foo { int* a; int* b; }; std::atomic<struct foo*> foo_head[10]; int foo_array[10][10]; // consume operation starts a dependency chain, which escapes this function [[carries_dependency]] struct 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) { struct 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 }

二次

另见

memory_order (C++11)defines memory ordering constraints for the given atomic operation (typedef)

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/原子/KILE[医]依赖性