命名空间
变体
操作

std::jthread::hardware_concurrency

来自 cppreference.cn
< cpp‎ | thread‎ | jthread
 
 
并发支持库
线程
(C++11)
(C++20)
this_thread 命名空间
(C++11)
(C++11)
(C++11)
协同取消
互斥
(C++11)
通用锁管理
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
条件变量
(C++11)
信号量
闩锁和屏障
(C++20)
(C++20)
期物
(C++11)
(C++11)
(C++11)
(C++11)
安全回收
(C++26)
Hazard 指针
原子类型
(C++11)
(C++20)
原子类型的初始化
(C++11)(C++20 中已弃用)
(C++11)(C++20 中已弃用)
内存顺序
(C++11)(C++26 中已弃用)
原子操作的自由函数
原子标志的自由函数
 
 
static unsigned int hardware_concurrency() noexcept;
(自 C++20 起)

返回实现支持的并发线程数。该值应仅被视为提示。

目录

[edit] 参数

(无)

[edit] 返回值

支持的并发线程数。如果该值未明确定义或不可计算,则返回 0

[edit] 示例

#include <iostream>
#include <thread>
 
int main()
{
    unsigned int n = std::jthread::hardware_concurrency();
    std::cout << n << " concurrent threads are supported.\n";
}

可能的输出

4 concurrent threads are supported.

[edit] 参见

避免伪共享的最小偏移量
促进真共享的最大偏移量
(常量) [编辑]