Is a single-threaded application running on only one CPU

I am developing a single-threaded application on a machine with 8 processors, and when a heavy operation occurs, the processor load looks like this:

enter image description here

Is there any way in the .NET Framework to split the work of this single thread (automatically) into other CPUs?

+5
source share
7 answers

It is not guaranteed that any one thread will always work on one core. But he guaranteed that he would work only on one core at a time . But it can work on one core before the context switch and resume after switching context to another core. Each slice of time that your thread receives can be allocated to another core.

+6
source

Does one streaming application work on only one processor?

As others noted, optional. However, this thread will only work one core at a time.

Is there a possibility in the .NET infrastructure to share work on other processors?

Yes..NET has the Parallel and Parallel LINQ classes. Please note that you must split the work yourself (into small pieces), and then the .NET framework will handle the work balancing between several threads automatically.

+5
source

Even a process with one thread may or may not always run this thread on the same CPU. Of course, the total CPU usage for this process cannot exceed 100% of a single core. But 100% can be distributed across many cores, like on a machine. Thus, you can see, for example, 50% use on two different cores instead of 100% on just one, 25% on four different cores, etc.

+2
source

The .NET garbage collector will run in a different thread, the GUI will be if you use WinForms / WPF, and the OS will do all kinds of work in other threads to help a single-threaded application run faster.

+1
source

A single-threaded application runs on only one core of your processor, so it works when you have several processors and you just get more cores, which makes your computer more powerful. You use only one core on all processors.

+1
source

I know this is an old thread, but I came here with the same problem and another reason / solution.

If you run your program through Visual Studio Debugger (VS2012 here), it seems that your threads are connected to one core. To use all available kernels, I had to run it directly from the executable or from the windows cmd command prompt.

It may be very specific, but hope this helps.

-1
source

No, it will always work in one processor / core and may change depending on the scheduler.

You can also use async and wait , and they will help with the fluidity of your application.

You looked at Task , this is a very easy way to create threads.

 Task.Run(() => { // Do something that will take a long time Thread.Sleep(10000); }); 
-3
source

Source: https://habr.com/ru/post/1209503/


All Articles