Community
cancel
Showing results for 
Search instead for 
Did you mean: 
yaumeileng
Beginner
135 Views

How to bind a pthread to a specific logical processor with Hyper-Threading support

Hi,

I have written a C program that creates multiple threads using pthread_create.

How can I bind these pthreads to specific logical processor that support Hyper-Threading?

I have came across sched_setaffinity that can bind the current process to specific processor. But how can I bind the pthreads created to bind on specific processor? Can pthread bind to logical processors or only a process can do so?

-meileng-
0 Kudos
1 Reply
Ioannis_V_
Beginner
135 Views

Hello Meileng,

I believe that sched_setaffinity() can be used for POSIX threads under Linux. Although a 'man sched_setaffinity' says that it can be applied only to processes, an 'info sched_setaffinity' and the latest manual of glibc say the following:

int sched_setaffinity(pid_t pid, const cpu_set_t *cpuset)
This function installs the affinity mask pointed to by cpuset for the process or thread with the ID pid. If successful the function returns zero and the scheduler will in future take the affinity information into account.


Notice that it says "process or thread". Moreover, I have used it in my own programs and it seems to work even with POSIX threads.

Hope that this helps,

Ioannis
Reply