Namespaces
Variants

Standard library header <semaphore> (C++20)

From cppreference.net
Standard library headers

이 헤더는 스레드 지원 라이브러리의 일부입니다.

클래스

음수가 아닌 리소스 카운트를 모델링하는 세마포어
(클래스 템플릿)
오직 두 가지 상태만을 가지는 세마포어
(typedef)

시놉시스

namespace std {
  template<ptrdiff_t LeastMaxValue = /* implementation-defined */>
    class counting_semaphore;
  using binary_semaphore = counting_semaphore<1>;
}

클래스 템플릿 std::counting_semaphore

namespace std {
  template<ptrdiff_t LeastMaxValue = /* implementation-defined */>
  class counting_semaphore {
  public:
    static constexpr ptrdiff_t max() noexcept;
    constexpr explicit counting_semaphore(ptrdiff_t desired);
    ~counting_semaphore();
    counting_semaphore(const counting_semaphore&) = delete;
    counting_semaphore& operator=(const counting_semaphore&) = delete;
    void release(ptrdiff_t update = 1);
    void acquire();
    bool try_acquire() noexcept;
    template<class Rep, class Period>
      bool try_acquire_for(const chrono::duration<Rep, Period>& rel_time);
    template<class Clock, class Duration>
      bool try_acquire_until(const chrono::time_point<Clock, Duration>& abs_time);
  private:
    ptrdiff_t counter;          // 설명용
  };
}