最終更新日時(UTC):
が更新

履歴 編集

function
<semaphore>

std::counting_semaphore::コンストラクタ(C++20)

constexpr explicit counting_semaphore(ptrdiff_t desired); // (1)
counting_semaphore(const counting_semaphore&) = delete;   // (2)

counting_semaphoreオブジェクトの構築

  • (1) : カウンタ初期値をdesiredとして、counting_semaphoreオブジェクトの初期化を行う。
  • (2) : コピーコンストラクタ。コピー不可。

事前条件

desired >= 0 かつ desired <= max()

例外

投げない

#include <semaphore>

// カウンタ 初期値0/最大値10 のセマフォを定義
std::counting_semaphore<10> sem{0};

// カウンタ 初期値1/最大値1 の(バイナリ)セマフォを定義
// このセマフォはミューテックス相当の排他制御に用いられる
std::counting_semaphore<1> mtx{1};

int main() {}

出力

バージョン

言語

  • C++20

処理系