POSIX等价的boost ::螺纹:: hardware_concurrency的 [英] POSIX equivalent of boost::thread::hardware_concurrency
本文介绍了POSIX等价的boost ::螺纹:: hardware_concurrency的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:结果
<一href=\"http://stackoverflow.com/questions/150355/programmatically-find-the-number-of-cores-on-a-machine\">Programmatically找到一台机器内核数
什么是POSIX或x86,x86-64的特定系统调用来确定线程的最大数量,系统可以在不超额认购运行吗?谢谢你。
What is the POSIX or x86, x86-64 specific system call to determine the max number of threads the system can run without over-subscription? Thank you.
推荐答案
它采用C兼容的结构,那么为什么不直接使用实际的code? [库/线程/ src目录/ * / thread.cpp]
It uses C-compatible constructs, so why not just use the actual code? [libs/thread/src/*/thread.cpp]
pthread库:
unsigned thread::hardware_concurrency()
{
#if defined(PTW32_VERSION) || defined(__hpux)
return pthread_num_processors_np();
#elif defined(__APPLE__) || defined(__FreeBSD__)
int count;
size_t size=sizeof(count);
return sysctlbyname("hw.ncpu",&count,&size,NULL,0)?0:count;
#elif defined(BOOST_HAS_UNISTD_H) && defined(_SC_NPROCESSORS_ONLN)
int const count=sysconf(_SC_NPROCESSORS_ONLN);
return (count>0)?count:0;
#elif defined(_GNU_SOURCE)
return get_nprocs();
#else
return 0;
#endif
}
在窗口:
unsigned thread::hardware_concurrency()
{
SYSTEM_INFO info={{0}};
GetSystemInfo(&info);
return info.dwNumberOfProcessors;
}
这篇关于POSIX等价的boost ::螺纹:: hardware_concurrency的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文