atomic_flag_notify_all

atomic_flag_notify_all (대기 중인 모든 스레드 깨우기)

주어진 std::atomic_flag에서 원자 대기 중인 모든 스레드를 깨우는 자유 함수예요. C++20부터 있어요.

출처: cppreference

본문

atomic_flag_notify_all은 원자 통지(notifying) 연산을 수행해요.

void atomic_flag_notify_all( std::atomic_flag* object ) noexcept;        // (1)
void atomic_flag_notify_all( volatile std::atomic_flag* object ) noexcept; // (2)

*object에서 대기 중인 스레드(즉 std::atomic_flag_wait(), atomic_flag_wait_explicit(), 또는 atomic_flag::wait()로 블록된 스레드)가 있으면 전부 깨워요. 없으면 아무 일도 하지 않아요. object->notify_all()과 동등해요.

  • 매개변수 object: 통지할 atomic_flag 객체 포인터.
  • 반환 값: 없음.

이런 변화 감지 방식은 단순 폴링이나 순수 스핀락보다 훨씬 효율적일 때가 많아요. 스레드가 CPU를 소모하며 회전하는 대신 블록했다가 통지로 깨어나니까요.

wait/notify_one/notify_all을 짝으로 해서 생산자-소비자나 이벤트 신호 패턴을 스핀 없이 구현할 수 있어요.

더 알아보기 (Learn more)

cppreference