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

线程类 更多...

#include <thread.hpp>

struct  id
 线程唯一标识符类 更多...
struct  hook
 线程生命周期钩子 更多...

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 (thread &&other) noexcept
 移动构造函数
threadoperator= (thread &&other) noexcept
 移动赋值运算符
 ~thread ()
 析构函数
NEFORCE_NODISCARD id get_id () const noexcept
 获取线程标识符
NEFORCE_NODISCARD native_handle_type native_handle () const noexcept
 获取原生句柄
NEFORCE_NODISCARD bool joinable () const noexcept
 检查线程是否可被等待
void join ()
 等待线程结束
void detach ()
 分离线程
bool set_name (const char *name)
 设置线程名称
bool name (char *buffer, size_t size) const
 获取线程名称
void swap (thread &other) noexcept
 交换两个线程对象

静态 Public 成员函数

static bool set_name (native_handle_type handle, const char *name)
 设置指定线程的名称
static bool name (native_handle_type handle, char *buffer, size_t size)
 获取指定线程的名称

详细描述

线程类

提供跨平台的线程管理功能,支持线程创建、等待、分离、ID获取等操作。 线程对象可移动但不可复制。

在文件 thread.hpp65 行定义.

构造及析构函数说明

◆ thread() [1/3]

thread::thread ( )
defaultnoexcept

默认构造函数

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

引用了 is_same_v , 以及 thread().

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

◆ thread() [2/3]

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传递给可调用对象的参数
异常
thread_exception如果线程创建失败

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

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

在文件 thread.hpp302 行定义.

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

◆ thread() [3/3]

thread::thread ( thread && other)
noexcept

移动构造函数

参数
other要移动的线程对象

引用了 thread().

◆ ~thread()

thread::~thread ( )

析构函数

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

成员函数说明

◆ detach()

void thread::detach ( )

分离线程

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

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

◆ get_id()

NEFORCE_NODISCARD id thread::get_id ( ) const
inlinenoexcept

获取线程标识符

返回
线程标识符

在文件 thread.hpp335 行定义.

◆ join()

void thread::join ( )

等待线程结束

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

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

◆ joinable()

NEFORCE_NODISCARD bool thread::joinable ( ) const
inlinenoexcept

检查线程是否可被等待

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

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

在文件 thread.hpp349 行定义.

◆ name() [1/2]

bool thread::name ( char * buffer,
size_t size ) const

获取线程名称

参数
buffer存储名称的缓冲区
size缓冲区大小
返回
是否获取成功

引用了 size().

被这些函数引用 name(), set_name() , 以及 set_name().

◆ name() [2/2]

bool thread::name ( native_handle_type handle,
char * buffer,
size_t size )
static

获取指定线程的名称

参数
handle线程句柄
buffer存储名称的缓冲区
size缓冲区大小
返回
是否获取成功

引用了 handle() , 以及 size().

◆ native_handle()

NEFORCE_NODISCARD native_handle_type thread::native_handle ( ) const
inlinenoexcept

获取原生句柄

返回
平台特定的线程句柄

在文件 thread.hpp341 行定义.

◆ operator=()

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

移动赋值运算符

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

引用了 thread().

◆ set_name() [1/2]

bool thread::set_name ( const char * name)

设置线程名称

参数
name线程名称
返回
是否设置成功
异常
thread_exception如果线程不可被等待

引用了 name().

被这些函数引用 set_name().

◆ set_name() [2/2]

bool thread::set_name ( native_handle_type handle,
const char * name )
static

设置指定线程的名称

参数
handle线程句柄
name线程名称
返回
是否设置成功

引用了 handle() , 以及 name().

◆ swap()

void thread::swap ( thread & other)
noexcept

交换两个线程对象

参数
other要交换的线程对象

引用了 thread().


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