views:

92

answers:

1

Possible Duplicate:
Will Multi threading increase the speed of the calculation on Single Processor

Hello all, I am reposting my question on Multithreading on Single core processor.

Original question is: http://stackoverflow.com/questions/2856239/will-multi-threading-increase-the-speed-of-the-calculation-on-single-processor

I have been asked a question, At any given time, only one thread is allowed to run on a single core. If so, why people use multithreading in a application. Lets say you are running console application and It is very much possible to write the application to run on the main thread. But still people go for multithreading.

A: 

It may not be faster for "pure" CPU work, but many tasks involve things that are not on the CPU (e.g. accessing file systems, networks, interacting with the user, etc). Even on a single core system, using multiple threads allows you to have one thread waiting on a file system access, one waiting on a network operation, one waiting for the user to respond and so on.

So while using multiple threads won't make a CPU-intensive process faster, it can make your application more responsive (that is, it can respond to user interaction "faster" because it's not blocked waiting for a network operation to complete, say).

Note that technically asynchronous operations will be even faster than using multiple blocking threads (because you don't have the overhead of context switching), but the multiple blocking threads paradigm is usually simpler to understand than asynchronous programming.

Dean Harding
Thanks for your reply. But I would like to how asynchronous operations are better than multithreading. If I am not wrong, asynchronous operations run on different thread. Again there must be context switching right. Please post article link or answers about how asynchronous programming is better than multithreading.Thanks for your time.
Harsha