Creating One Thread Per Processor

suggest change

Environment.ProcessorCount Gets the number of logical processors on the current machine.

The operating system schedules those threads. They may land on different logical processors, on one processor, or on some mix of the two. Creating the threads does not pin each one to its own processor.

using System;
using System.Threading;

class MainClass {
    static void Main() {
        for (int i = 0; i < Environment.ProcessorCount; i++) {
            var thread = new Thread(Secondary);
            thread.Start(i);
        }
        
    }

    static void Secondary(object threadNumber) {
        System.Console.WriteLine("Hello World from thread: " + threadNumber);
    }
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents