When is multi-threading not a good idea? [closed] When is multi-threading not a good idea? [closed] multithreading multithreading

When is multi-threading not a good idea? [closed]


  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 the web server 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 multi-processor server and a web based app, no need again for multi threads because the web server handles it.

In total, if you use multiple threads for other than un-freezing desktop apps and any other generic answer, you will make the app slower if you have a single core machine due to the threads interrupting each other.

Why? 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.


To paraphrase an old quote: A programmer had a problem. He thought, "I know, I'll use threads." Now the programmer has two problems. (Often attributed to JWZ, but it seems to predate his use of it talking about regexes.)

A good rule of thumb is "Don't use threads, unless there's a very compelling reason to use threads." Multiple threads are asking for trouble. Try to find a good way to solve the problem without using multiple threads, and only fall back to using threads if avoiding it is as much trouble as the extra effort to use threads. Also, consider switching to multiple threads if you're running on a multi-core/multi-CPU machine, and performance testing of the single threaded version shows that you need the performance of the extra cores.


Multi-threading is a bad idea if:

  • Several threads access and update the same resource (set a variable, write to a file), and you don't understand thread safety.

  • Several threads interact with each other and you don't understand mutexes and similar thread-management tools.

  • Your program uses static variables (threads typically share them by default).

  • You haven't debugged concurrency issues.