views:

832

answers:

5

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

+21  A: 

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.

MontyGomery
In an academic sense you are absolutely correct. However, no program on earth is 100% CPU-work which means in practice, multiple threads can have a positive impact even though theres only one computing unit
Isak Savo
+1  A: 

Regardless of the number of CPUs available, if you require preemptive multitasking and/or applications with asynchronous components (i.e. pretty much anything that combines a responsive GUI with a non-trivial amount of computation or continuous I/O processing), multithreading performs much better than the alternative, which is to use multiple processes for each application.

This is because threads in the same process can exchange data much more efficiently than can multiple processes, because they share the same memory context.

See this Wikipedia article on computer multitasking for a fairly concise discussion of these issues.

McKenzieG1
+6  A: 

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.

Bill Michell
+1  A: 

Yes, there is a benefit of using multiple threads (or processes) on a single CPU - if one thread is busy waiting for something, others can continue doing useful work.

However this can be offset by the overhead of task switching. You'll have to benchmark and/or profile your application on production grade hardware to find out.

MarkR
+1  A: 

Absolutely! If you do any kind of I/O, there is great advantage to having a multithreaded system. While one thread wait for an I/O operation (which are relatively slow), another thread can do useful work.

Benoit