PDA

View Full Version : linux library needed for pthread_setaffinity_np


tanmay.anjaria
01-31-08, 02:36 AM
Hello,

I'm using a quad processor system. I want a program running on my PC having four threads and each of them running on different processors.

I'm using function "pthread_setaffinity_np" for that. while compiling, it gives an error saying "undefined reference to : pthread_setaffinity_np"

Can anyone tell me which library should be included for "pthread_setaffinity_np" ?

Thanks in advance... :)

Tanmay

mlauss
01-31-08, 04:10 AM
Did you add "-lpthread" (a.k.a tell gcc to use the libpthread library) to the compiler commandline?

tanmay.anjaria
01-31-08, 05:02 AM
yes, I'm using -lpthread currently...

command line goes like this...

gcc -lm -lpthread test.c

mlauss
01-31-08, 07:35 AM
Your libc appears to be missing NPTL bits

This is from glibc-2.7 (which is NPTL only):
# nm /lib/libpthread-2.7.so | grep setaffinity
0000e0c0 t __pthread_attr_setaffinity_new
0000e1c0 t __pthread_attr_setaffinity_old
0000ded0 t __pthread_setaffinity_new
0000df80 t __pthread_setaffinity_old
0000e0c0 T pthread_attr_setaffinity_np@@GLIBC_2.3.4
0000e1c0 T pthread_attr_setaffinity_np@GLIBC_2.3.3
0000ded0 T pthread_setaffinity_np@@GLIBC_2.3.4
0000df80 T pthread_setaffinity_np@GLIBC_2.3.3

Also, maybe it works with
#include<nptl/pthread.h>
since I'm told pthread_setaffinity_np() is a wrapper around
the sched_setaffinity() call (you know the "static inline" kind of wrapper ;-) )