Search code examples
.netvb.netmultithreading.net-3.5

How many threads can I run concurrently on Windows?


A comment to another of my questions says that I can only run "so many" threads concurrently, a notion which I have seen elsewhere.

As a threading novice, how can I determine the maximum number of threads to use? Or is this a "how long is a piece of string" question? What does it depends on? Hardware config or what?

(VB in MS Visual Studio with .Net 3.5, if that matters)


Update: is anyone aware of any s/w tool which could suggest a number of threads (or tasks), or should I just code my own which keeps trying different numbers until throughput drops?


[Upperdate] Almost seven years later & we now have a software recommendations site, so I asked if there is a tool to help with this.


Solution

  • It depends on hardware as you're (probably) not using a theoretical computer but a physical hardware one, so you have limited resources.

    Read: Does Windows have a limit of 2000 threads per process?

    Furthermore, even if you could run 5000+ threads, depending on your hardware, that could run much slower than a 10 thread equivalent program. I think you should take a look at thread pooling.