pthread_getaffinity_np issue

Konstantin Belousov kostikbel at gmail.com
Thu Sep 24 18:32:53 UTC 2015


On Thu, Sep 24, 2015 at 11:11:27AM -0700, Jason Schulz wrote:
> I'm having an issue using the non-posix thread affinity methods.  Specifically, I'm having trouble using CPU_COUNT.  I'm trying to use the following code to get the current number of processors in a processes affinity...
> 
> 
> 
> long cs = 0;
> 
> #if defined(HAVE_LINUX) || defined(HAVE_FREEBSD)
> 
> pthread_t this = pthread_self();
> 
> cpu_set_t cpus;
> 
> CPU_ZERO(&cpus);
> 
> int err = pthread_getaffinity_np(this, sizeof(cpus), &cpus);
> 
> if (err)
>   return err;
> 
> cs = (long) CPU_COUNT(&cpus);
> 
> 
> 
> However, I get the compiler error...
> 
> 
> 
> clang -DHAVE_CONFIG_H -I.      -g -O2 -D_THREAD_SAFE -pthread -pipe -std=c99 -D_XOPEN_SOURCE=700 -pedantic -Wall -Wextra -Wsign-conversion -Wconversion -Werror -MT thread.o -MD -MP -MF .deps/thread.Tpo -c -o thread.o thread.c
> thread.c:85:15: error: implicit declaration of function '__bitcountl' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
>   cs = (long) CPU_COUNT(&cpus);
>               ^
> /usr/include/sys/cpuset.h:63:24: note: expanded from macro 'CPU_COUNT'
> #define CPU_COUNT(p)                    BIT_COUNT(CPU_SETSIZE, p)
>                                         ^
> /usr/include/sys/bitset.h:185:14: note: expanded from macro 'BIT_COUNT'
>                 __count += __bitcountl((p)->__bits[__i]);               \
>                            ^
> 1 error generated.
> 
> 
> 
> I'm able to use CPU_ISSET to the same effect, but obviously I'd rather use CPU_COUNT.  Suggestions?
> 

Show the minimal example demonstrating the issue, specify the version
of the system and which you use.  My guess is that you did not added
#include <sys/types.h> before including sys/cpuset.h.


More information about the freebsd-threads mailing list