From cppreference.com
template<classT>Tkill_dependency(Ty)noexcept;(since C++11)
(constexpr since C++26)
(deprecated in C++26)Informs the compiler that the dependency tree started by an
atomic load operation does not extend past the return value of std::kill_dependency; that is, the argument does not carry a dependency into the return value.
This may be used to avoid unnecessary
fences when the dependency chain leaves function scope (and the function does not have the [[
]] attribute).
(until C++26)Simply returns y. This function template is deprecated.
(since C++26)Parameters
y - the expression whose return value is to be removed from a dependency tree Return value
Returns y, no longer a part of a dependency tree(until C++26).
Examples
file1.cpp:structFoo{int*a;int*b;};std::atomic<Foo*>foo_head[10];intfoo_array[10][10];// consume operation starts a dependency chain, which escapes this function[[carries_dependency]]Foo*f(inti){returnfoo_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)intg(int*x,int*y[[carries_dependency]]){returnstd::kill_dependency(foo_array[*x][*y]);}file2.cpp:[[carries_dependency]]structFoo*f(inti);intg(int*x,int*y[[carries_dependency]]);intc=3;voidh(inti){Foo*p;p=f(i);// dependency chain started inside f continues into p without undue acquiredo_something_with(g(&c,p->a));// p->b is not brought in from the cachedo_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}See also