• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

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

    履歴 編集

    function template
    <thread>

    std::this_thread::sleep_for

    namespace std {
    namespace this_thread {
      template <class Rep, class Period>
      void sleep_for(const chrono::duration<Rep, Period>& rel_time);
    }}
    

    概要

    指定した相対時間だけ現スレッドをブロックする。

    効果

    引数 rel_timeで指定した相対時間だけ現在のスレッド、すなわちこの関数を呼び出したスレッド自身をブロックする。

    指定した相対時間 以上 の時間が経過すると、現スレッドのブロックが解除されて後続処理の実行が開始される。なお、タイマーの精度は処理系依存。

    同期操作

    特に他操作に対して同期する規定はない。

    例外

    #include <thread>
    #include <chrono>
    
    int main()
    {
      // 3分間 現スレッドをブロック(Sleep)
      std::this_thread::sleep_for(std::chrono::minutes(3));
    
      return 0;
    }
    

    出力

    バージョン

    言語

    • C++11

    処理系

    参照