Namespaces
Variants

std:: atomic_flag_wait, std:: atomic_flag_wait_explicit

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
atomic_flag_wait atomic_flag_wait_explicit
(C++20) (C++20)
헤더 파일에 정의됨 <atomic>
void atomic_flag_wait ( const atomic_flag * object, bool old ) noexcept ;
(1) (C++20부터)
void atomic_flag_wait ( const volatile atomic_flag * object,
bool old ) noexcept ;
(2) (C++20부터)
void atomic_flag_wait_explicit ( const atomic_flag * object,
bool old, std:: memory_order order ) noexcept ;
(3) (C++20부터)
void atomic_flag_wait_explicit ( const volatile atomic_flag * object,
bool old, std:: memory_order order ) noexcept ;
(4) (C++20부터)

원자적 대기 연산을 수행합니다.

object - > test ( std:: memory_order_seq_cst ) 또는 object - > test ( order ) old 와 비교하고, 값이 동일하면 * object std::atomic_flag::notify_one() 또는 std::atomic_flag::notify_all() 에 의해 통지될 때까지(또는 스레드가 가짜로 차단 해제될 때까지) 블록합니다. 이 작업은 값 비교 결과가 다를 때까지 반복됩니다.

1,2) 메모리 동기화 순서는 std:: memory_order_seq_cst 입니다.
3,4) 메모리 동기화 순서는 order 입니다.
만약 order std:: memory_order_release std:: memory_order_acq_rel 중 하나라면, 동작은 정의되지 않습니다.

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

목차

매개변수

object - 확인하고 대기할 atomic flag에 대한 포인터
old - atomic flag가 더 이상 포함하지 않는지 확인할 값
order - 메모리 동기화 순서

반환값

(없음)

참고 사항

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

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

예제

참고 항목

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