最大线程数 Windows Threads limit

2019-01-19  本文已影响0人  我的随笔

这周跑一个测试程序的时候出错,发现错误信息是:“线程创建失败”。网上搜索了一下,原来是线程数有限制。

这个限制数和程序本身以及操作系统有关。

我的测试程序是32位的,运行电脑是64位的Windows 10。

32位线程默认栈空间大小是1M,在我的64位的电脑上,32位的程序的最大虚拟内存是4G,所以线程数最多是4096个(4G/1M)。但是下图所示,总线程数超过了4096,我想应该是有部分操作系统自身的64位线程在运行,我们看到的是总数。也不知道对不对,希望知道的麻烦告诉我一下,谢谢。 

64位的程序虚拟内存可达8T,目前来说可以支持一个巨大的线程数。但是受限于实际的物理内存大小。如果内存限制忽略不计的话,下面的表格可以最大线程数

参考链接: https://blogs.technet.microsoft.com/markrussinovich/2009/07/05/pushing-the-limits-of-windows-processes-and-threads/

We are running 32-bit threads on 64-bit machine.

32-bit threads have a default of 1MB reserved for stack.

32-bit processes are given 4GB of address space when they run on 64-bit Windows, the number of threads should be roughly 4096 (4GB divided by 1MB)

Why we have more in the following picture? I think there should be some 64-bit processes/threads were running when we ran the test case.  That's reasonable. But I don't know if it is correct. Can anyone tells me about it.

 64-bit processes have a much larger user-mode address space (8TB). But available memory is obviously still a limiter. We have the threads as the following diagram without pysical memory limit.

Ref: https://blogs.technet.microsoft.com/markrussinovich/2009/07/05/pushing-the-limits-of-windows-processes-and-threads/ 

上一篇下一篇

猜你喜欢

热点阅读