MSTL 1.4.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
thread类 参考

线程类 更多...

#include <thread.hpp>

struct  id
 线程唯一标识符类 更多...

Public 类型

using native_handle_type
 系统线程句柄类型

Public 成员函数

 thread () noexcept=default
 默认构造函数
template<typename F, typename... Args, typename = enable_if_t<!is_same_v<decay_t<F>, thread>>>
 thread (F &&f, Args &&... args)
 从可调用对象构造线程
 thread (const thread &)=delete
threadoperator= (const thread &)=delete
 thread (thread &&other) noexcept
 移动构造函数
threadoperator= (thread &&other) noexcept
 移动赋值运算符
 ~thread ()
 析构函数
MSTL_NODISCARD id get_id () const noexcept
 获取线程标识符
MSTL_NODISCARD native_handle_type native_handle () const noexcept
 获取原生句柄
MSTL_NODISCARD bool joinable () const noexcept
 检查线程是否可被等待
void join ()
 等待线程结束
void detach ()
 分离线程
void swap (thread &other) noexcept
 交换两个线程对象

详细描述

线程类

在文件 thread.hpp30 行定义.

构造及析构函数说明

◆ thread() [1/4]

thread::thread ( )
defaultnoexcept

默认构造函数

构造一个不表示任何线程的thread对象。

引用了 thread().

被这些函数引用 operator=(), operator=(), swap(), thread(), thread(), thread() , 以及 thread().

◆ thread() [2/4]

template<typename F, typename... Args, typename = enable_if_t<!is_same_v<decay_t<F>, thread>>>
thread::thread ( F && f,
Args &&... args )
inlineexplicit

从可调用对象构造线程

模板参数
F可调用对象类型
Args参数类型
参数
f要执行的可调用对象
args传递给可调用对象的参数
异常
system_exception如果线程创建失败

创建一个新线程,并在线程中执行带参数的可调用对象。

注解
线程的执行目标报错将导致进程终止

在文件 thread.hpp214 行定义.

引用了 _MSTL, apply(), forward(), make_tuple(), move() , 以及 thread().

◆ thread() [3/4]

thread::thread ( const thread & )
delete
注解
禁止复制构造

引用了 thread().

◆ thread() [4/4]

thread::thread ( thread && other)
noexcept

移动构造函数

参数
other要移动的线程对象

引用了 thread().

◆ ~thread()

thread::~thread ( )

析构函数

注解
如果线程处于可被等待状态则终止进程。

成员函数说明

◆ detach()

void thread::detach ( )

分离线程

异常
system_exception如果线程不可被等待或分离失败

使线程在后台独立运行,线程结束后自动释放资源。

◆ get_id()

MSTL_NODISCARD id thread::get_id ( ) const
inlinenoexcept

获取线程标识符

返回
线程标识符

在文件 thread.hpp254 行定义.

◆ join()

void thread::join ( )

等待线程结束

异常
system_exception如果线程不可被等待或等待失败

阻塞当前线程,直到目标线程执行完毕。

◆ joinable()

MSTL_NODISCARD bool thread::joinable ( ) const
inlinenoexcept

检查线程是否可被等待

返回
线程是否处于可被等待状态

线程在创建后、被等待结束或分离前是可被等待的。

在文件 thread.hpp268 行定义.

◆ native_handle()

MSTL_NODISCARD native_handle_type thread::native_handle ( ) const
inlinenoexcept

获取原生句柄

返回
平台特定的线程句柄

在文件 thread.hpp260 行定义.

◆ operator=() [1/2]

thread & thread::operator= ( const thread & )
delete
注解
禁止复制赋值

引用了 thread().

◆ operator=() [2/2]

thread & thread::operator= ( thread && other)
noexcept

移动赋值运算符

参数
other要移动的线程对象
返回
当前对象的引用

引用了 thread().

◆ swap()

void thread::swap ( thread & other)
inlinenoexcept

交换两个线程对象

参数
other要交换的线程对象

在文件 thread.hpp290 行定义.

引用了 _MSTL, swap() , 以及 thread().


该类的文档由以下文件生成: