[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: How to find number of processors?



On Sat, Jan 09, 2010 at 02:08:07PM -0600, Steve M. Robbins wrote:
> Hello,
> 
> I'm seeking advice -- preferably in the form of a tested patch :-)
> for a build failure specific to kFreeBSD [1,2]:
> 
>   libs/thread/src/pthread/thread.cpp: In static member function 'static unsigned int boost::thread::hardware_concurrency()':
>   libs/thread/src/pthread/thread.cpp:384: error: 'get_nprocs' was not declared in this scope
>   ...failed gcc.compile.c++ bin.v2/libs/thread/build/gcc-4.4.2/release/debug-symbols-on/threading-multi/pthread/thread.o...
> 
> The code in question is:
> 
>     unsigned thread::hardware_concurrency()
>     {
> #if defined(PTW32_VERSION) || defined(__hpux)
>         return pthread_num_processors_np();
> #elif defined(_GNU_SOURCE)
>         return get_nprocs();

It seems that get_nprocs() is always implemented by Glibc.  Worst-case it'd
be a dummy stub.  I'd just try to figure out why <sys/sysinfo.h> is not
included or not providing its declaration.

OTOH:

> #elif defined(__APPLE__) || defined(__FreeBSD__)
>         int count;
>         size_t size=sizeof(count);
>         return sysctlbyname("hw.ncpu",&count,&size,NULL,0)?0:count;

Adding __FreeBSD_kernel__ here should also work.  But the previous solution is
much cleaner IMHO.

-- 
Robert Millan

  "Be the change you want to see in the world" -- Gandhi


Reply to: