這周跑一個測試程序的時候出錯,發(fā)現(xiàn)錯誤信息是:“線程創(chuàng)建失敗”。網(wǎng)上搜索了一下,原來是線程數(shù)有限制。
這個限制數(shù)和程序本身以及操作系統(tǒng)有關(guān)。
我的測試程序是32位的,運(yùn)行電腦是64位的Windows 10。
32位線程默認(rèn)??臻g大小是1M,在我的64位的電腦上,32位的程序的最大虛擬內(nèi)存是4G,所以線程數(shù)最多是4096個(4G/1M)。但是下圖所示,總線程數(shù)超過了4096,我想應(yīng)該是有部分操作系統(tǒng)自身的64位線程在運(yùn)行,我們看到的是總數(shù)。也不知道對不對,希望知道的麻煩告訴我一下,謝謝。?
64位的程序虛擬內(nèi)存可達(dá)8T,目前來說可以支持一個巨大的線程數(shù)。但是受限于實(shí)際的物理內(nèi)存大小。如果內(nèi)存限制忽略不計的話,下面的表格可以最大線程數(shù)
參考鏈接:?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/?