I'd like to specify the cpu-affinity of a particular pthread. All the references I've found so far deal with setting the cpu-affinity of a process (pid_t) not a thread (pthread_t). I tried some experiments passing pthread_t's around and as expected they fail. Am I trying to do something impossible? If not, can you send a pointer please? Thanks a million.
相关问题
- slurm: use a control node also for computing
- How to let a thread communicate with another activ
- Why it isn't advised to call the release() met
- ThreadPoolTaskScheduler behaviour when pool is ful
- Custom TaskScheduler, SynchronizationContext?
相关文章
- Difference between Thread#run and Thread#wakeup?
- Java/Spring MVC: provide request context to child
- Threading in C# , value types and reference types
- RMI Threads prevent JVM from exiting after main()
- How to get CPU serial under Linux without root per
- Is it possible to run 16 bit code in an operating
- Async task does not work properly (doInBackground
- Android, Volley Request, the response is blocking
This is a wrapper I've made to make my life easier. Its effect is that the calling thread gets "stuck" to the core with id
core_id
:The scheduler will change the cpu affinity as it sees fit; to set it persistently please see cpuset in /proc file system.
http://man7.org/linux/man-pages/man7/cpuset.7.html
Or you can write a short program that sets the cpu affinity periodically (every few seconds) with sched_setaffinity
Assuming linux:
The interface to setting the affinity is - as you've probably already discovered:
Passing 0 as the pid, and it'll apply to the current thread only, or have other thread report their kernel pid with the linux specific call pid_t gettid(void); and pass that in as the pid.
Quoting the man page
In POSIX environment you can use cpusets to control which CPUs can be used by processes or pthreads. This type of control is called CPU affinity.
The function 'sched_setaffinity' receives pthread IDs and a cpuset as parameter. When you use 0 in the first parameter, the calling thread will be affected
Please find the below example program to cpu-affinity of a particular pthread.
Please add appropriate libs.
Compile above program with -D_GNU_SOURCE flag.