プログラム内にルーチンを記述することで、これを確実に行うことができます。
ただし、オペレーティングシステムはこれらのものを管理するための最良の候補であるため、それを行うべきではありません. つまり、ユーザーモードプログラムはそれをやろうとすべきではありません。
ただし、場合によっては、負荷分散を達成し、真のマルチスレッド マルチコアの問題 (データ レーシング/キャッシュ コヒーレンス...) を見つけるために (実際に上級ユーザー向けに) 行うことができます。これは、異なるスレッドが異なるプロセッサで実際に実行されるためです。 .
そうは言っても、それでも達成したい場合は、次の方法でそれを行うことができます。(Windows OS) の疑似コードを提供していますが、Linux でも簡単に実行できます。
#define MAX_CORE 256
processor_mask[MAX_CORE] = {0};
core_number = 0;
Call GetLogicalProcessorInformation();
// From Here we calculate the core_number and also we populate the process_mask[] array
// which would be used later on to set to run different threads on different CORES.
for(j = 0; j < THREAD_POOL_SIZE; j++)
Call SetThreadAffinityMask(hThread[j],processor_mask[j]);
//hThread is the array of handles of thread.
//Now if your number of threads are higher than the actual number of cores,
// you can use reset the counters(j) once you reach to the "core_number".
上記のルーチンが呼び出された後、スレッドは常に次のように実行されます。
Thread1-> Core1
Thread2-> Core2
Thread3-> Core3
Thread4-> Core4
Thread5-> Core5
Thread6-> Core6
Thread7-> Core7
Thread8-> Core8
Thread9-> Core1
Thread10-> Core2
...............
これらの概念の詳細については、マニュアル/MSDN を参照してください。