What's the maximum number of threads in Windows Server 2003? What's the maximum number of threads in Windows Server 2003? windows windows

What's the maximum number of threads in Windows Server 2003?


First I would advise reading this:http://blogs.msdn.com/oldnewthing/archive/2007/03/01/1775759.aspx

then http://blogs.msdn.com/oldnewthing/archive/2005/07/29/444912.aspx

To summarise, the limitation is normally stack space (which must be in contiguous blocks) and since every thread consumes this scattered about you rapidly run out of contiguous blocks.On 64 bit machines and operating systems this is much less of a problem.

Mitigation strategies exist but will only go so far (and rely on you not using much stack per thread)

As a rough guide:

  • creating tens is almost certain to work
  • hundreds is probable on current server and desktop hardware but risky
  • thousands will almost certainly fail.

You likely shouldn't need to create more than ten anyway (and if you really do need to you should know this information already)


The best answer I've heard when asking such questions is:

It doesn't matter, and if you find that it does matter, you need to rethink what you're doing so that it doesn't matter.


Note that you should examine your design closely if you are concerned about hitting this limit!!!!!!!!

The answer to your "More Important Question" of what happens is OutOfMemoryException.

Not exactly a direct answer, but here's some code to find out the limit. It could be available memory dependent though. Would be interested in seeing other OS/cpu/mem results.

Feel free to edit and add your machine in:

  • Windows 7, VS2008, dual core, 2gb mem: 1,465 then crash with OutOfMemoryException

        int i = 0;    try    {        while (true)        {            new Thread(new ThreadStart(() => Thread.Sleep(int.MaxValue))).Start();            i++;        }    }    catch (Exception ex)    {        Console.WriteLine(i);        Console.WriteLine(ex.ToString());    }