是否有一个API来获取Linux中可用的CPU数量?我的意思是,不使用/ proc/cpuinfo或任何其他sys-node文件......
我已经使用sched.h找到了这个实现:
int GetCPUCount()
{
cpu_set_t cs;
CPU_ZERO(&cs);
sched_getaffinity(0, sizeof(cs), &cs);
int count = 0;
for (int i = 0; i < 8; i++)
{
if (CPU_ISSET(i, &cs))
count++;
}
return count;
}
Run Code Online (Sandbox Code Playgroud)
但是,使用公共库是不是更高级别?
我正在使用此代码使用可变参数模板创建多个函数包装器:
// Compile with g++ -std=c++0x $(pkg-config sigc++-2.0 --cflags --libs) test.cpp -o test
#include <iostream>
#include <type_traits>
#include <sigc++/sigc++.h>
template <typename R, typename G, typename... Ts>
class FuncWrapper
{
public:
FuncWrapper(G object, std::string const& name, sigc::slot<R, Ts...> function) {};
};
int main()
{
FuncWrapper<void, int, int, bool, char> tst(0, "test", [] (int a, bool b, char c) {});
return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)
由于已知问题,此代码正确编译了clang ++,但没有使用g ++编译:
test.cpp:9:73:抱歉,未实现:无法将'Ts ...'扩展为固定长度的参数列表
我知道gcc-4.7应该正确处理,但我现在无法升级...所以我想要一个解决方法来Ts...正确解压缩.我测试过什么样的问题在这里提出这一个,但他们似乎并不在这里解决问题.