Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple threads and performance on a single CPU

Is here any performance benefit to using multiple threads on a computer with a single CPU that does not having hyperthreading?

like image 367
readonly Avatar asked Sep 06 '08 18:09

readonly


People also ask

Can a single core cpu run multiple threads?

Yes you can do multithreading on a single processor system. In multi-processor system , multiple threads execute , simultaneously on different cores. Eg- If there are two threads and two cores , then each thread would run on individual core.

Is multithreading faster on a single core?

In fact, you should expect the program to run significantly slower than the single-threaded version. Multithreading generally makes programs run slower, not faster.

Is more threads on a CPU better?

If you want to get the most out of the CPU use, then you should always purchase a CPU that has more threads. A Thread is a sequence of instructions that can run at the same time. This allows for faster performance by processing multiple instructions simultaneously rather than one at a time.

How many threads can run on a single processor?

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.


2 Answers

In terms of speed of computation, No. In fact things will slow down due to the overhead of managing the threads.

In terms of responsiveness, yes. You can for example have one thread wait on an IO operation and have another run a GUI at the same time.

like image 159
MontyGomery Avatar answered Oct 21 '22 15:10

MontyGomery


It depends on your application. If it spends all its time using the CPU, then multithreading will just slow things down - though you may be able to use it to be more responsive to the user and thus give the impression of better performance.

However, if your code is limited by other things, for example using the file system, the network, or any other resource, then multithreading can help, since it allows your application to behave asynchronously. So while one thread is waiting for a file to load from disk, another can be querying a remote webserver and another redrawing the GUI, while another is doing various calculations.

Working with multiple threads can also simplify your business logic, since you don't have to pay so much attention to how various independent tasks need to interleave. If the operating system's scheduling logic is better than yours, then you may indeed see improved performance.

like image 20
Bill Michell Avatar answered Oct 21 '22 15:10

Bill Michell