Namespaces
Variants

std::atomic_flag:: wait

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
(C++11) (deprecated in C++26)
Free functions for atomic operations
Free functions for atomic flags
void wait ( bool old, std:: memory_order order =
std:: memory_order_seq_cst ) const noexcept ;
(1) (C++20부터)
(C++26부터 constexpr)
void wait ( bool old,

std:: memory_order order =

std:: memory_order_seq_cst ) const volatile noexcept ;
(2) (C++20부터)

원자적 대기 연산을 수행합니다. 다음과 같은 단계를 반복적으로 수행하는 것처럼 동작합니다:

  • this - > test ( order ) 의 값을 old 의 값과 비교합니다.
    • 두 값이 동일한 경우, * this notify_one() 또는 notify_all() 에 의해 통지받거나, 스레드가 spuriously unblock될 때까지 블록합니다.
    • 그렇지 않은 경우, 즉시 반환합니다.

이러한 함수들은 기본 구현이 불필요하게 차단 해제되는 경우에도 값이 변경된 경우에만 반환됨이 보장됩니다.

만약 order std:: memory_order_relaxed , std:: memory_order_consume , std:: memory_order_acquire 또는 std:: memory_order_seq_cst 가 아닌 경우, 동작은 정의되지 않습니다.

목차

매개변수

old - atomic_flag 객체가 더 이상 포함하지 않는지 확인할 값
order - 적용할 메모리 순서 제약 조건

참고 사항

이러한 형태의 변경 감지는 단순 폴링이나 순수 스핀락보다 종종 더 효율적입니다.

ABA 문제 로 인해, old 에서 다른 값으로 일시적으로 변경되었다가 다시 old 로 돌아오는 변화가 감지되지 않을 수 있으며, 차단이 해제되지 않을 수 있습니다.


예제

참고 항목

(C++20)
원자적 객체를 대기 중인 스레드 중 최소 하나에 알림
(public member function)
(C++20)
원자적 객체를 대기 중인 모든 스레드에 알림
(public member function)
atomic_flag_wait에서 대기 중인 스레드에 알림
(function)
atomic_flag_wait에서 대기 중인 모든 스레드에 알림
(function)