首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::thread::hardware_concurrency

static unsigned hardware_concurrency();

?

(since C++11)

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

参数

%280%29

返回值

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

例外

noexcept规格:

noexcept

二次

代码语言:javascript
复制
#include <iostream>
#include <thread>
 
int main() {
    unsigned int n = std::thread::hardware_concurrency();
    std::cout << n << " concurrent threads are supported.\n";
}

二次

可能的产出:

二次

代码语言:javascript
复制
4 concurrent threads are supported.

二次

另见

hardware_destructive_interference_sizehardware_constructive_interference_size (C++17)

min offset to avoid false sharingmax offset to promote true sharing (constant)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com