std::jthread:: hardware_concurrency
From cppreference.net
C++
Concurrency support library
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
std::jthread
| Member functions | ||||
| Observers | ||||
|
jthread::hardware_concurrency
|
||||
| Operations | ||||
| Stop token handling | ||||
| Non-member functions | ||||
|
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.
参见
|
避免伪共享的最小偏移量
促进真共享的最大偏移量 (常量) |