Namespaces
Variants

std:: kill_dependency

From cppreference.net
Concurrency support library
Threads
(C++11)
(C++20)
this_thread namespace
(C++11)
(C++11)
Cooperative cancellation
Mutual exclusion
Generic lock management
Condition variables
(C++11)
Semaphores
Latches and Barriers
(C++20)
(C++20)
Futures
(C++11)
(C++11)
(C++11)
Safe reclamation
Hazard pointers
Atomic types
(C++11)
(C++20)
Initialization of atomic types
(C++11) (deprecated in C++20)
(C++11) (deprecated in C++20)
Memory ordering
kill_dependency
(C++11) (deprecated in C++26)
Free functions for atomic operations
Free functions for atomic flags
헤더에 정의됨 <atomic>
template < class T >
T kill_dependency ( T y ) noexcept ;
(C++11부터)
(C++26부터 constexpr)
(C++26에서 사용 중단됨)

컴파일러에 std::memory_order_consume 원자적 로드 연산으로 시작된 종속성 트리가 std::kill_dependency 의 반환값을 넘어 확장되지 않음을 알립니다. 즉, 인자가 반환값으로 종속성을 전달하지 않습니다.

종속성 체인이 함수 범위를 벗어날 때 (그리고 함수가 [[ carries_dependency ]] 속성을 갖지 않을 때) 불필요한 std::memory_order_acquire 펜스를 피하기 위해 사용될 수 있습니다.

(C++26까지)

단순히 y 를 반환합니다. 이 함수 템플릿은 사용이 중단되었습니다(deprecated).

(C++26부터)

목차

매개변수

y - 의존성 트리에서 반환값을 제거할 표현식

반환값

반환 값 y , 더 이상 의존성 트리의 일부가 아님 (C++26까지) .

예제

file1.cpp:
struct Foo
{
    int* a;
    int* b;
};
std::atomic<Foo*> foo_head[10];
int foo_array[10][10];
// consume 연산은 이 함수를 벗어나는 의존성 체인을 시작합니다
[[carries_dependency]] Foo* f(int i)
{
    return foo_head[i].load(memory_order_consume);
}
// 의존성 체인은 오른쪽 매개변수를 통해 이 함수로 들어오며
// 함수가 끝나기 전에 제거됩니다 (따라서 추가적인 acquire 연산이 발생하지 않음)
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); // f 내부에서 시작된 의존성 체인이 과도한 acquire 없이 p로 계속 전파됨
    do_something_with(g(&c, p->a)); // p->b는 캐시에서 가져오지 않음
    do_something_with(g(p->a, &c)); // 왼쪽 인수는 carries_dependency 속성을 가지지 않음
                                    // 메모리 acquire 펜스가 발행될 수 있음
                                    // p->b는 g()가 진입되기 전에 가시성이 확보됨
}

참고 항목

주어진 원자적 연산에 대한 메모리 순서 제약 조건을 정의함
(열거형)
C 문서 for kill_dependency