std::jthread::hardware_concurrency
来自 cppreference.cn
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] 参见
避免伪共享的最小偏移量 促进真共享的最大偏移量 (常量) |