Thursday, March 11, 2010

When is multi-threading not a good idea?

Posted by Scott on 18. September 2008 11:40

 
I was recently asked when not to use mulit-threading so I gave them the best answer possible.  I think my answer below fits the bill pretty nicely.
  1. On a single processor machine and a desktop application, you use multi threads so you don't freeze the app but for nothing else really.
  2. On a single processor server and a web based app, no need for multi threading because IIS handles most of it.
  3. On a multi processor machine and desktop app, you are suggested to use multi threads and parallel programming. Make as many threads as there are processors.
  4. On a mulit processor server and a web based app, no need again for multi threads because IIS handles it.

In total, if you use multi threads for other than un-freezing desktop apps and any other generic answer, you will make the app slower over time IF you have a single core machine.

Why? Well because of the hardware switches. It takes time for the hardware to switch between threads in total. On a multi core box, go ahead and use 1 thread for each core and you will greatly see a ramp up in speed at the start and over time as the cores heat up.

kick it on DotNetKicks.com
If you liked this post, please be sure to subscribe to my RSS Feed.

Share/Save/Bookmark

Comments

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
Loading