views:

66

answers:

3

In general the operating system takes care of allocating threads to cores. I wonder whether there is a way for the program to be invloved in this allocation.

In other words: Is there an API (for either the Linux or Win32 platforms) enabling to create a thread that is associated with a specific core?

+2  A: 

On Windows, SetThreadAffinityMask. In general, don't do this. The OS is almost certainly better at this than you are.

Roger Lipscombe
+1  A: 

On Linux, sched_set_affinity and pthread_attr_setaffinity_np.

Martin B
A: 

Note that Windows has facilities to set the affinity of the process, but also each of its threads independently. Linux only offers facilities to set the affinity of the process.

For Windows, the process function is SetProcessAffinityMask. Also Windows has the notion of "ideal" processor (SetThreadIdealProcessor), which is much better to use if you don't know what you are doing (although the notion does not work in XP).

Juice