Namespaces
Variants

Standard library header <thread> (C++11)

From cppreference.net
Standard library headers

このヘッダは スレッドサポート ライブラリの一部です。

目次

インクルード

(C++20)
三方比較演算子 サポート

名前空間

this_thread 現在の実行スレッドにアクセスする関数を提供

クラス

(C++11)
個別のスレッドを管理する
(クラス)
(C++20)
std::thread 自動結合とキャンセル機能をサポート
(クラス)
std::hash を特殊化
(クラステンプレートの特殊化)

関数

std::swap アルゴリズムを特殊化
(関数)
(C++20で削除) (C++20で削除) (C++20で削除) (C++20で削除) (C++20で削除) (C++20)
2つの thread::id オブジェクトを比較
(関数)
thread::id オブジェクトをシリアライズ
(関数テンプレート)
std::this_thread 名前空間で定義
(C++11)
実装に対してスレッドの実行再スケジュールを提案
(関数)
(C++11)
現在のスレッドのスレッドIDを返す
(関数)
(C++11)
現在のスレッドの実行を指定時間停止
(関数)
現在のスレッドの実行を指定時点まで停止
(関数)

概要

#include <compare>
namespace std {
  // クラス thread
  class thread;
  void swap(thread& x, thread& y) noexcept;
  // クラス jthread
  class jthread;
  // 名前空間 this_thread
  namespace this_thread {
    thread::id get_id() noexcept;
    void yield() noexcept;
    template<class Clock, class Duration>
    void sleep_until(const chrono::time_point<Clock, Duration>& abs_time);
    template<class Rep, class Period>
    void sleep_for(const chrono::duration<Rep, Period>& rel_time);
  }
}

クラス std::thread

namespace std {
  class thread
  {
  public:
    // クラス thread::id
    class id;
    using native_handle_type = /* 実装定義 */;
    // 構築/コピー/破棄
    thread() noexcept;
    template<class F, class... Args>
    explicit thread(F&& f, Args&&... args);
    ~thread();
    thread(const thread&) = delete;
    thread(thread&&) noexcept;
    thread& operator=(const thread&) = delete;
    thread& operator=(thread&&) noexcept;
    // メンバ関数
    void swap(thread&) noexcept;
    bool joinable() const noexcept;
    void join();
    void detach();
    id get_id() const noexcept;
    native_handle_type native_handle();
    // 静的メンバ関数
    static unsigned int hardware_concurrency() noexcept;
  };
}

クラス std::jthread

namespace std {
  class jthread
  {
  public:
    // 型
    using id                 = thread::id;
    using native_handle_type = thread::native_handle_type;
    // コンストラクタ、ムーブ、代入
    jthread() noexcept;
    template<class F, class... Args>
    explicit jthread(F&& f, Args&&... args);
    ~jthread();
    jthread(const jthread&) = delete;
    jthread(jthread&&) noexcept;
    jthread& operator=(const jthread&) = delete;
    jthread& operator=(jthread&&) noexcept;
    // メンバ関数
    void swap(jthread&) noexcept;
    bool joinable() const noexcept;
    void join();
    void detach();
    id get_id() const noexcept;
    native_handle_type native_handle();
    // ストップトークン処理
    stop_source get_stop_source() noexcept;
    stop_token get_stop_token() const noexcept;
    bool request_stop() noexcept;
    // 特殊化アルゴリズム
    friend void swap(jthread& lhs, jthread& rhs) noexcept;
    // 静的メンバ
    static unsigned int hardware_concurrency() noexcept;
  private:
    stop_source ssource; // 説明専用
  };
}

クラス std::thread::id

namespace std {
  class thread::id
  {
  public:
    id() noexcept;
  };
  bool operator==(thread::id x, thread::id y) noexcept;
  strong_ordering operator<=>(thread::id x, thread::id y) noexcept;
  template<class CharT, class Traits>
  basic_ostream<CharT, Traits>& operator<<(basic_ostream<CharT, Traits>& out,
                                           thread::id id);
  template<class CharT>
  struct formatter<thread::id, CharT>;
  // ハッシュサポート
  template<class T>
  struct hash;
  template<>
  struct hash<thread::id>;
}