By default, a thread's stack has to reserve 1M of memory space
And the memory space available in a process is only 2 G, so theoretically a maximum of 2048 threads can be opened in a process
But memory certainly cannot be fully used as a thread stack, so the actual number is smaller than this value.
You can also change the default stack size by connecting it to a smaller number so that you can open more threads.
If you change the default stack size to 512K, you can theoretically open up to 4,096 threads.
Even if the physical memory is large, a thread in a process can always be limited by the 2GB of memory space.
Let's say your machine has 64GB of physical memory, but the memory space for each process is 4GB, where the user's state is 2GB.
In the same machine, the number of threads can be limited by memory. Each thread object has to stand in non-page memory, but not page memory is also limited, when the non-page memory is depleted, it can not create a thread.
If the physical memory is very large, the number of threads that can run within the same machine will be more restrictive.
Write a program under Windows, a process fork out 2000 or so threads will be abnormal exit, why? This problem arises because of the WINDOWS32 bit system, the maximum virtual memory a process can use is 2G, and the default line of one thread stacks stacksize 1024K (1M) so that when the number of threads approaches 2000, 2000*1024k= 2G (approx.), memory resources are equivalent to exhaustion. If your server-side program is designed to create a thread with a client connection request, there are 2000 restrictions (in the case of hardware memory and CPU count).
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/Delphi/