Results 1 to 4 of 4
Hi
I am using glib version 1.2.10.
I came to know from somewhere that "pthread_attr_setaffinity_np(3)" does not work on this version for POSIX threads. Following error was coming:
(.text+0x112): undefined ...
- 04-29-2010 #1Just Joined!
- Join Date
- Apr 2010
- Posts
- 4
Unable to change affinity with sched_setaffinity and pthread_attr_setaffinity_np
Hi
I am using glib version 1.2.10.
I came to know from somewhere that "pthread_attr_setaffinity_np(3)" does not work on this version for POSIX threads. Following error was coming:
(.text+0x112): undefined reference to `pthread_attr_setaffinity_np'
collect2: ld returned 1 exit status
So I tried to set affinity thru: sched_setaffinity(pid, sizeof(cpu_set_t), &set),
where "pid" is of type pid_t (actually pid=getpid() --> from unistd.h or syscall( __NR_gettid )--> from sys/syscall.h )
and "set" is of type cpu_set_t ...
Unfortuantely, sched_setaffinity returned -1 (I dono why?).
Then I tried to use macros: CPU_ZERO, CPU_SET etc, but following error occured:
(.text+0x3f): undefined reference to `CPU_ZERO'
Although pthread_attr_setaffinity_np was not defined in pthread.h but CPU_* macros are there in sched.h. So why is it giving the error?
Then I tried to use syscall for CPU_ZERO ,i.e., syscall ( __CPU_ZERO ( &set) ), but then following error came:
error: expected expression before 'do'
All I want to do is to run 2 threads on two different processors. I cannot change the glib version.
A little help here will be greatly appreciated.
Thanks in advance.
- 04-30-2010 #2Linux Newbie
- Join Date
- Mar 2010
- Posts
- 121
First-off, glib has nothing to do with the rest of your post - I don't know why you think it does...
Anyway, a couple of questions:
1) When you tried to use pthread_attr_setaffinity_np, did you specify -pthtread or -lpthread on the command-line?
2) With regards to the above quote, if you look at the man page for sched_setaffinity, you'll see that if -1 is returned then the global variable errno is set to show a reason. You can print this out by calling perror() with a descriptive const char* argument (like "sched_setaffinity failed") - do that, and you'll know why this call is failing.
- 05-03-2010 #3Just Joined!
- Join Date
- Apr 2010
- Posts
- 4
@John
Thanks for replying.
if glib veriosn is greater than 2.4.6 then we can use pthread_attr_getaffinity_np, otherwise, we can't.
I m using -lpthread.
When I ued perror, I came up with following error merssage (corresponding to sched_getaffinity) :
Bad address
- 05-06-2010 #4Just Joined!
- Join Date
- Apr 2010
- Posts
- 4
Well, I forgot to
#define _GNU_SOURCE
thats why CPU_* macros were not linked.
Now problem is resolved.


Reply With Quote
