The maximum number of threads a process in a Windows system can allow

Source: Internet
Author: User
Tags thread

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/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.