一个进程在Windows中可以拥有的最大线程数是多少 [英] What is the maximum number of threads a process can have in windows

查看:2434
本文介绍了一个进程在Windows中可以拥有的最大线程数是多少的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个windows进程中,每次使用的线程有任何限制。如果是这样,每个进程可以使用的最大线程数是多少?

In a windows process is there any limit for the threads to be used at a time. If so what is the maximum number of threads that can be used per process?

推荐答案

但有两个实际的限制:


  1. 堆栈的虚拟空间。例如在32位中,进程的虚拟空间是4GB,但是只有大约2G可用于一般使用。默认情况下,每个线程将保留1MB的堆栈空间,因此顶部值为2000个线程。当然,你可以改变栈的大小,使其更低,以便更多的线程适合( dwStackSize in CreateThread 或链接器命令中的选项 / STACK )。如果使用64位系统,这个限制实际上会消失。

  2. 调度程序开销。一旦你读了几千个线程,只是调度它们将吃掉几乎100%的CPU时间,所以他们大多是无用的。这不是硬性限制,只是您的程序会更慢和更慢的线程你创建更多。

  1. The virtual space for the stacks. For example in 32-bits the virtual space of the process is 4GB, but only about 2G are available for general use. By default each thread will reserve 1MB of stack space, so the top value are 2000 threads. Naturally you can change the size of the stack and make it lower so more threads will fit in (parameter dwStackSize in CreateThread or option /STACK in the linker command). If you use a 64-bits system this limit practically dissapears.
  2. The scheduler overhead. Once you read the thousands of threads, just scheduling them will eat nearly 100% of your CPU time, so they are mostly useless anyway. This is not a hard limit, just your program will be slower and slower the more threads you create.

这篇关于一个进程在Windows中可以拥有的最大线程数是多少的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆