- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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-
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-
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page