首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::kill_dependency

Defined in header <atomic>

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

实例

二次

代码语言:javascript
复制
//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]);
}

二次

二次

代码语言:javascript
复制
//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)

代码语言:txt
复制
 © cppreference.com

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

扫码关注腾讯云开发者

领取腾讯云代金券