What is the maximum number of threads that can be generated in Windows 8.1, and what factors can limit the number of threads?
-
2If you need to know this, you're doing something wrong. – Harry Johnston Aug 21 '14 at 05:19
-
Actually its the question asked by Microsoft with options (A)4000, (B)40,000 (C)1000 (D)400. in Intern Written examination, so i haven't assumed Microsoft to be wrong – Mercury Aug 22 '14 at 08:29
-
Fair enough; let me rephrase. If you need to know this *while programming* you're doing something wrong. Strictly speaking I'm not sure that examination questions are on-topic here, but Hans has posted a good answer, so I'll let it slide. :-) Note to reviewers: this is definitely not a super user question. – Harry Johnston Aug 22 '14 at 09:57
-
e) Nobody cares, as long as the box is not regularly overloaded, (ie. more ready threads than cores). – Martin James Aug 22 '14 at 16:57
3 Answers
Like most limits in Windows, this is limited by available memory. A 32-bit process keels over somewhat shy of 2000 threads when all available virtual memory is occupied by the stacks of the threads (1 MB each). A 64-bit process is limited by the size of the paging file, needed to commit the allocation. Many thousands, it depends on how fast the paging file can grow to meet the needs of the program. There is also a limit imposed by the kernel's paged memory pool, each thread has a kernel stack so that it can make kernel calls, typically 24 KB per thread.
These limits are far beyond the number of balls a programmer can keep in the air without dropping one on his foot. He'll be limping around for a long time, threading bugs are exceedingly hard to troubleshoot.
Mark Russinovich explores the limits in this excellent blog post.

- 922,412
- 146
- 1,693
- 2,536
I believe you may be thinking of this somewhat wrong. Threads are limited by your CPU and how many can fit on ram, not Windows OS. Also, the way you attack concurrent programming is largely dependent on how the programming language your using addresses the issue. For instance c++ using the stl libraries vs c++ using mpi(process based) are very different.
Each CPU has a physical/ virtual thread limit it can do at once. Any more than that number will cause a over-subscription of threads, forcing task switching. For instance my PC has eight threads (4 cores/ 4 virtual), if I create 10 thread I will get them BUT 2 will always not be running at any time. This will for the machine to do extra task switching to meet all 10 threads. Also, keep in mind your program isn't the only one in the PC running.
To find the max number of thread you can run in C++ using the stl:
#include<iostream>
#include<thread>
using namespace std;
int main()
{
cout << thread::hardware_concurrency();
cin.get();
return 0;
}
Though I recommend using a programming language such a C# that abstracts the threading for you using automatic thread pools and tasks. This will make it easier to learn the concepts.
Also, processes and thread are different. For a great explanation of this difference I suggest the following Link:
-
My i7 box has 77 processes and 1255 threads ATM. Everything is fine. – Martin James Aug 22 '14 at 16:52
-
my pc has more than 8 processes alive, BUT can only run 8 at a time. The scheduler in windows will switch between execution of threads and process to compensate, without a problem. – Aug 22 '14 at 20:15
-
The point I was trying to make was 'What is the maximum number of threads that can be generated in Windows 8.1' is not the same question as 'What is the maximum number of running threads that can be generated in Windows 8.1' Nearly all threads on typical desktop systems are rearely ready or running, but usually blocked on I/O or inter-thread comms. – Martin James Aug 23 '14 at 00:47
Question from Microsoft intern:
Possible ans: Depends on RAM size and Processor.

- 663
- 1
- 6
- 14