为什么会出现使用std ::螺纹:: hardware_concurrency()和boost ::螺纹:: hardware_concurrency()有区别吗? [英] Why is there a difference using std::thread::hardware_concurrency() and boost::thread::hardware_concurrency()?

查看:1120
本文介绍了为什么会出现使用std ::螺纹:: hardware_concurrency()和boost ::螺纹:: hardware_concurrency()有区别吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题本身的描述是pretty简单。我测试的std ::线程库的区别在C ++ 11和boost ::线程库。

这些输出:

 的#include<&iostream的GT;
#包括LT&;螺纹>
#包括LT&;升压/ thread.hpp>诠释主(){
  性病::法院LT&;<的std ::螺纹:: hardware_concurrency()<<的std :: ENDL;
  性病::法院LT&;<提高::螺纹:: hardware_concurrency()<<的std :: ENDL;
  返回0;
}

给我不同的结果:

  0
4

这是为什么?

PS:gcc包的版本是4.6.2-1.fc16(x86_64的)。我使用

  G ++ test.cc -Wall -std =的C ++ 0x -lboost_thread-MT -lpthread


解决方案

在审查/ usr / include目录/ C ++ / 4.6.2 /线程

,可以看出,实现实际上是:

  //返回暗示的硬件线程上下文数的值。
静态无符号整型
hardware_concurrency()
{返回0; }

所以,问题就迎刃而解了。它只是没有在GCC中实现另一个特点4.6.2

The description of the problem itself is pretty simple. I'm testing the differences of std::thread library in C++11 and boost::thread library.

The output of these:

#include <iostream>
#include <thread>
#include <boost/thread.hpp>

int main() {
  std::cout << std::thread::hardware_concurrency() << std::endl;
  std::cout << boost::thread::hardware_concurrency() << std::endl;
  return 0;
}

gives me different results:

0
4

Why is that?

PS: The version of the gcc package is 4.6.2-1.fc16 (x86_64). I'm using

g++ test.cc -Wall -std=c++0x -lboost_thread-mt -lpthread

解决方案

After reviewing /usr/include/c++/4.6.2/thread

it can be seen that the implementation is actually:

// Returns a value that hints at the number of hardware thread contexts.
static unsigned int
hardware_concurrency()
{ return 0; }

So problem solved. It's just another feature that hasn't been implemented in gcc 4.6.2

这篇关于为什么会出现使用std ::螺纹:: hardware_concurrency()和boost ::螺纹:: hardware_concurrency()有区别吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆