Reputation: 43
I have a process which create 3 threads. I want to assign 1 thread to 1 cpu core (CPU has 8 physical cores) and those cores only run my threads. Because i want to make sure my computation thread always run with highest priority.
For example: Thread 1 is assigned to core 1, and core 1 is only run thread 1. Core 0,2,3,4,5,6,7 is freely to run others threads from others processes.
Does any library support this? or anyone know how to do it?
Upvotes: 1
Views: 3688
Reputation: 1869
Apart from SetThreadAffinityMask, there is also SetThreadIdealProcessor which is a bit more forgiving in case you make bad decisions on which core you run it on (i.e. several cpu-hungry apps locked to the same core).
Upvotes: 0
Reputation: 28872
On Linux you have sched_setaffinity and sched_getaffinity. http://linux.die.net/man/2/sched_setaffinity
Upvotes: 2
Reputation: 4770
This is generally called processor or thread affinity and is something you probably will have the handle at the platform level.
On windows, you can use the SetThreadAffinityMask function.
Upvotes: 2