CppDS.com

C++ 98 11 14 17 20 手册

std::jthread::hardware_concurrency

来自cppreference.com
< cpp‎ | thread‎ | jthread

 
 
线程支持库
线程
(C++11)
(C++20)
(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++11)
(C++11)
条件变量
(C++11)
信号量
闩与屏障
(C++20)
(C++20)
future
(C++11)
(C++11)
(C++11)
(C++11)
 
 
[[nodiscard]] static unsigned int hardware_concurrency() noexcept;
(C++20 起)

返回实现支持的并发线程数。应该只把该值当做提示。

参数

(无)

返回值

支持的并发线程数。若该值非良定义或不可计算,则返回 0

示例

#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.

参阅

避免假共享的最小偏移
促使真共享的最大偏移
(常量)
关闭