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 ?
There is no such thing as a single thread running on multiple cores simultaneously. It doesn't mean, however, that instructions from one thread cannot be executed in parallel. There are mechanisms called instruction pipelining and out-of-order execution that allow it.
The answer is: It depends. On a system with multiple processors or CPU cores (as is common with modern processors), multiple processes or threads can be executed in parallel. On a single processor, though, it is not possible to have processes or threads truly executing at the same time.
A single CPU core can have up-to 2 threads per core. For example, if a CPU is dual core (i.e., 2 cores) it will have 4 threads. And if a CPU is Octal core (i.e., 8 core) it will have 16 threads and vice-versa.
Single threaded processes contain the execution of instructions in a single sequence. In other words, one command is processes at a time. The opposite of single threaded processes are multithreaded processes. These processes allow the execution of multiple parts of a program at the same time.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With