首页 > 代码库 > 测试CPU核心个数

测试CPU核心个数

//测试CPU核心个数#if !defined (_WIN32) && !defined (_WIN64)#define LINUX#include <unistd.h>#else#define WINDOWS#include <windows.h>#endifunsigned core_count(){  unsigned count = 1; // 至少一个  #if defined (LINUX)  count = sysconf(_SC_NPROCESSORS_CONF);  #elif defined (WINDOWS)  SYSTEM_INFO si;  GetSystemInfo(&si);  count = si.dwNumberOfProcessors;  #endif  return count;}#include <iostream>int main(){  unsigned sz = core_count();  std::cout << sz << (1 == sz ? "core" : "cores") << std::endl;}

http://www.cppblog.com/Chipset/archive/2009/02/20/74403.html