C++ 参考手册
- C++11
 - C++14
 - C++17
 - C++20
 - C++ 编译器支持情况表
 - 独立与宿主实现
 - C++ 语言
 - C++ 关键词
 - 预处理器
 - C++ 标准库头文件
 - 标准库头文件 <ctime>
 - 标准库头文件 <cstring>
 - 标准库头文件 <set>
 - 标准库头文件 <cctype>
 - 标准库头文件 <cwctype>
 - 标准库头文件 <utility>
 - 标准库头文件 <queue>
 - 标准库头文件 <complex>
 - 标准库头文件 <iterator>
 - 标准库头文件 <algorithm>
 - 标准库头文件 <valarray>
 - 标准库头文件 <numeric>
 - 标准库头文件 <cmath>
 - 标准库头文件 <iosfwd>
 - 标准库头文件 <ios>
 - 标准库头文件 <iomanip>
 - 标准库头文件 <streambuf>
 - 标准库头文件 <istream>
 - 标准库头文件 <ostream>
 - 标准库头文件 <iostream>
 - 标准库头文件 <sstream>
 - 标准库头文件 <clocale>
 - 标准库头文件 <vector>
 - 标准库头文件 <deque>
 - 标准库头文件 <list>
 - 标准库头文件 <map>
 - 标准库头文件 <cwchar>
 - 标准库头文件 <locale>
 - 标准库头文件 <codecvt>
 - 标准库头文件 <bitset>
 - 标准库头文件 <functional>
 - 标准库头文件 <stdexcept>
 - 标准库头文件 <csignal>
 - 标准库头文件 <csetjmp>
 - 标准库头文件 <stack>
 - 标准库头文件 <cassert>
 - 标准库头文件 <cerrno>
 - 标准库头文件 <memory>
 - 标准库头文件 <typeindex>
 - 标准库头文件 <type_traits>
 - 标准库头文件 <chrono>
 - 标准库头文件 <initializer_list>
 - 标准库头文件 <tuple>
 - 标准库头文件 <scoped_allocator>
 - 标准库头文件 <cstdint>
 - 标准库头文件 <cinttypes>
 - 标准库头文件 <system_error>
 - 标准库头文件 <cuchar>
 - 标准库头文件 <array>
 - 标准库头文件 <forward_list>
 - 标准库头文件 <unordered_set>
 - 标准库头文件 <unordered_map>
 - 标准库头文件 <random>
 - 标准库头文件 <ratio>
 - 标准库头文件 <cfenv>
 - 标准库头文件 <regex>
 - 标准库头文件 <atomic>
 - 标准库头文件 <thread>
 - 标准库头文件 <mutex>
 - 标准库头文件 <future>
 - 标准库头文件 <condition_variable>
 - 标准库头文件 <any>
 - 标准库头文件 <optional>
 - 标准库头文件 <variant>
 - 标准库头文件 <memory_resource>
 - 标准库头文件 <string_view>
 - 标准库头文件 <charconv>
 - 标准库头文件 <execution>
 - 标准库头文件 <filesystem>
 - 标准库头文件 <concepts>
 - 标准库头文件 <coroutine>
 - 标准库头文件 <compare>
 - 标准库头文件 <version>
 - 标准库头文件 <source_location>
 - 标准库头文件 <format>
 - 标准库头文件 <span>
 - 标准库头文件 <ranges>
 - 标准库头文件 <bit>
 - 标准库头文件 <numbers>
 - 标准库头文件 <syncstream>
 - 标准库头文件 <stop_token>
 - 标准库头文件 <semaphore>
 - 标准库头文件 <latch>
 - 标准库头文件 <barrier>
 - 标准库头文件 <string>
 - 标准库头文件 <cstddef>
 - 标准库头文件 <limits>
 - 标准库头文件 <cfloat>
 - 标准库头文件 <climits>
 - 标准库头文件 <cstdlib>
 - 标准库头文件 <new>
 - 标准库头文件 <typeinfo>
 - 标准库头文件 <exception>
 - 标准库头文件 <cstdarg>
 - 标准库头文件 <ciso646>
 - 标准库头文件 <cstdalign>
 - 标准库头文件 <cstdbool>
 - 标准库头文件 <fstream>
 - 标准库头文件 <cstdio>
 - 标准库头文件 <strstream>
 - 标准库头文件 <shared_mutex>
 - 标准库头文件 <ccomplex>
 - 标准库头文件 <ctgmath>
 - 注释
 - 具名要求
 - 功能特性测试 (C++20)
 - 工具库
 - 类型支持(基本类型、RTTI、类型特性)
 - 概念库 (C++20)
 - 错误处理
 - 动态内存管理
 - 日期和时间工具
 - 字符串库
 - 容器库
 - 迭代器库
 - 范围库 (C++20)
 - 算法库
 - 数值库
 - 输入/输出库
 - 文件系统库
 - 本地化库
 - 正则表达式库
 - 原子操作库
 - 线程支持库
 - 实验性 C++ 特性
 - 有用的资源
 - 索引
 - std 符号索引
 - 协程支持 (C++20)
 - C++ 关键词
 
位置:首页 > C++ 参考手册 >C++ 标准库头文件 > 标准库头文件 <thread>
标准库头文件 <thread>
此头文件是线程支持库的一部分。
 类 | |
|    (C++11)  | 
  管理单独的线程  (类)  | 
|    (C++20)  | 
   有自动合并和取消支持的 std::thread   (类)  | 
 函数 | |
|    (C++11)  | 
   特化 std::swap 算法   (函数)  | 
|    (C++20 中移除)(C++20 中移除)(C++20 中移除)(C++20 中移除)(C++20 中移除)(C++20)  | 
   比较两个 thread::id 对象  (函数)  | 
  序列化 thread::id 对象 (函数模板)  | |
|   特化 std::hash  (类模板特化)  | |
 命名空间 | |
  this_thread
 | 
提供访问当前执行线程的函数 | 
 函数 | |
|   定义于命名空间  
std::this_thread | |
|    (C++11)  | 
  建议实现重新调度各执行线程  (函数)  | 
|    (C++11)  | 
  返回当前线程的线程 id  (函数)  | 
|    (C++11)  | 
   使当前线程的执行停止指定的时间段   (函数)  | 
|    (C++11)  | 
  使当前线程的执行停止直到指定的时间点   (函数)  | 
概要
namespace std { class thread; void swap(thread& x, thread& y) noexcept; bool operator==(thread::id x, thread::id y) noexcept; bool operator!=(thread::id x, thread::id y) noexcept; bool operator<(thread::id x, thread::id y) noexcept; bool operator<=(thread::id x, thread::id y) noexcept; bool operator>(thread::id x, thread::id y) noexcept; bool 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 T> struct hash; template <> struct hash<thread::id>; 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
class thread { public: // 类型: class id; typedef /* 由实现定义 */ 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 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; [[nodiscard]] bool joinable() const noexcept; void join(); void detach(); [[nodiscard]] id get_id() const noexcept; [[nodiscard]] native_handle_type native_handle(); // 停止记号处理 [[nodiscard]] stop_source get_stop_source() noexcept; [[nodiscard]] stop_token get_stop_token() const noexcept; bool request_stop() noexcept; // 特化的算法 friend void swap(jthread& lhs, jthread& rhs) noexcept; // 静态成员 [[nodiscard]] static unsigned int hardware_concurrency() noexcept; private: stop_source ssource; // 仅用于阐释 }; }
类 std::thread::id
class thread::id { public: id() noexcept; };