CodeRider
CodeRider

Reputation: 1824

What is the maximum number of threads a process can have in windows

In a windows process is there any limit for the threads to be used at a time. If so what is the maximum number of threads that can be used per process?

Upvotes: 32

Views: 49167

Answers (2)

Mats Petersson
Mats Petersson

Reputation: 129524

The actual limit is determined by the amount of available memory in various ways. There is no limit of "you can't have more than this many" of threads or processes in Windows, but there are limits to how much memory you can use within the system, and when that runs out, you can't create more threads.

See this blog by Mark Russinovich: http://blogs.technet.com/b/markrussinovich/archive/2009/07/08/3261309.aspx

Upvotes: 7

rodrigo
rodrigo

Reputation: 98516

There is no limit that I know of, but there are two practical limits:

  1. The virtual space for the stacks. For example in 32-bits the virtual space of the process is 4GB, but only about 2G are available for general use. By default each thread will reserve 1MB of stack space, so the top value are 2000 threads. Naturally you can change the size of the stack and make it lower so more threads will fit in (parameter dwStackSize in CreateThread or option /STACK in the linker command). If you use a 64-bits system this limit practically dissapears.
  2. The scheduler overhead. Once you read the thousands of threads, just scheduling them will eat nearly 100% of your CPU time, so they are mostly useless anyway. This is not a hard limit, just your program will be slower and slower the more threads you create.

Upvotes: 27

Related Questions