std::kill_dependency(3)
πΈ NAME πΈ
okay so this is the C++ Standard Libary page (yes, spelled like that in the manual, no cap) for std::kill_dependency β literally std::kill_dependency. π
β¨ Synopsis β¨
Defined in header <atomic>
template< class T > (since C++11)
T kill_dependency( T y ) noexcept;
Bestie, here's the whole vibe: this informs the compiler that the dependency tree started by an std::memory_order_consume 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 std::memory_order_acquire fences when the dependency chain leaves function scope (and the function does not have the [[carries_dependency]] attribute). literally so useful for those compiler-fence situations. π¦
π 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. periodt. β¨
π¦ Examples π¦
okay bestie, here's the example code exactly as the page gives it, because we do not mess with the source π
file1.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]);
}
file2.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
}
π See also π
memory_orderβ defines memory ordering constraints for the given atomic operation,(C++11)(enum).- C documentation for
kill_dependency.
mwah π this page is from http://cppreference.com, dated 2024.06.10, and it's the std::kill_dependency(3) page β bye bestie, go read your atomics π«Άβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms