Почему не все ядра загружены и, как сделать так, чтобы отдельный поток подавался на отдельное ядро? - C#
Формулировка задачи:
Создал 12 потоков, а как-то не все ядра загружены.
Процессор i7-3930K.
Вопрос. Почему не все ядра загружены и как сделать так, чтобы отдельный поток подавался на отдельное ядро?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
namespace ConsoleApplication1Thread
{
class Program
{
static void Main(string[] args)
{
ThreadProc();
Thread t2 = new Thread(ThreadProc);
t2.Start();
Thread t3 = new Thread(ThreadProc);
t3.Start();
Thread t4 = new Thread(ThreadProc);
t4.Start();
Thread t5 = new Thread(ThreadProc);
t5.Start();
Thread t6 = new Thread(ThreadProc);
t6.Start();
Thread t7 = new Thread(ThreadProc);
t7.Start();
Thread t8 = new Thread(ThreadProc);
t8.Start();
Thread t9 = new Thread(ThreadProc);
t9.Start();
Thread t10 = new Thread(ThreadProc);
t10.Start();
Thread t11 = new Thread(ThreadProc);
t11.Start();
Thread t12 = new Thread(ThreadProc);
t12.Start();
}
static void ThreadProc()
{
while (true)
Console.WriteLine("Поток");
}
}
}Решение задачи: «Почему не все ядра загружены и, как сделать так, чтобы отдельный поток подавался на отдельное ядро?»
textual
Листинг программы
[SecurityPermission(SecurityAction.Demand, Flags=SecurityPermissionFlag.ControlThread)]
public class MyUtility
{
[SecurityPermission(SecurityAction.Demand, Flags=SecurityPermissionFlag.ControlThread)]
public void PerformTask()
{
// Code that does not have thread affinity goes here.
//
Thread.BeginThreadAffinity();
//
// Code that has thread affinity goes here.
//
Thread.EndThreadAffinity();
//
// More code that does not have thread affinity.
}
}