標準庫標頭檔案 <semaphore> (C++20)
來自 cppreference.com
此標頭檔案是 執行緒支援 庫的一部分。
類 | |
(C++20) |
模擬非負資源計數的訊號量 (類模板) |
(C++20) |
僅有兩種狀態的訊號量 (型別定義) |
[編輯] 概要
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; // exposition only }; }