atomic_flag_notify_one

atomic_flag_notify_one (대기 중인 스레드 하나 깨우기)

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

출처: cppreference

본문

atomic_flag_notify_one은 원자 통지 연산을 수행해요.

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

*object에서 원자 대기 중(즉 std::atomic_flag_wait(), atomic_flag_wait_explicit(), 또는 atomic_flag::wait())인 스레드가 있으면 그중 적어도 하나를 깨워요. 없으면 아무 일도 하지 않아요. object->notify_one()과 동등해요.

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

notify_all이 모든 대기자를 깨우는 반면 notify_one은 하나만 깨워요. 하나의 작업을 하나의 대기자가 처리하는 작업 큐 같은 패턴에 맞아요.

이런 변화 감지는 폴링이나 순수 스핀락보다 효율적이에요. 대기자가 CPU를 태우며 회전하는 대신 블록 상태에서 통지로 깨어나니까요.

더 알아보기 (Learn more)

cppreference