Reputation: 409
I am developing a single threaded application on an 8 CPU machine and when a heavy operation happens the CPU utilization appears like this :
Does the .NET framework have some facility to divide the work of that single thread (automatically) into the other CPUs ?
Upvotes: 6
Views: 3094
Reputation: 54
I know that this is an old thread, but I arrived here with the same problem, and a different cause/solution.
If you launch your program through the Visual Studio Debugger (VS2012 here), it seems that your threads are bound to a single core. In order to use all the cores available, I had to launch it directly from the executable or from a windows cmd prompt.
May be very specific, but hope it helps.
Upvotes: 0
Reputation: 457147
Does a single threaded application run on only one CPU?
As others have noted, not necessarily. However, a given thread will only run on one core at a time.
Does .net framework have some facility to divide the work into the other CPUs?
Yes. .NET has the Parallel
class and Parallel LINQ. Note that you have to divide up the work yourself (into small pieces), and then the .NET framework will handle balancing the work between multiple threads automatically.
Upvotes: 5
Reputation: 4543
It's not guaranteed that any single thread will always run on the same core. But it's guaranteed that it will run only on one core at the same time. But it can run on one core till context switch, and resume after the context switch on another core. Each time-slice, your thread gets, may be allocated on another core.
Upvotes: 9
Reputation: 1496
No it will always run in one processor/core, and it might change depending on the scheduler.
You can also use async and await, and they will help with the fluidity of you application.
Have you looked into Task, its a very simple way of creating threads
Task.Run(() =>
{
// Do something that will take a long time
Thread.Sleep(10000);
});
Upvotes: -1
Reputation: 70701
Even a process with just one thread may or may not always run that one thread on the same CPU. The total CPU utilization for that process cannot exceed 100% of a single core, of course. But that 100% may be spread across as many cores as there are on the machine. So you may see e.g. 50% utilization on two different cores instead of 100% on just one, 25% on four different cores, etc.
Upvotes: 3
Reputation: 57
A single threaded application only runs on one core of your CPU so the way it works is when you have multiple CPU's your just getting more cores making your pc more powerful. Your only using one core on all of the CPU's.
Upvotes: 1
Reputation: 5063
The .NET garbage collector will run on another thread, the GUI will if you're doing WinForms/WPF, and the OS will be doing all kinds of work in other threads to help your single-threaded app run faster.
Upvotes: 1