如题,在保证性能稳定的前提下,一个进程最多可以有多少个线程?

解决方案 »

  1.   

    windows上线程栈需要1M空间,进程最大可以访问2G空间,自己就可以算出来(不过是理论上的)。经验上200以下
      

  2.   


    MSDN
    "Res
    The number of threads a process can create is limited by the available virtual memory. By default, every thread has one megabyte of stack space. Therefore, you can create at most 2,028 threads. If you reduce the default stack size, you can create more threads. However, your application will have better performance if you create one thread per processor and build queues of requests for which the application maintains the context information. A thread would process all requests in a queue before processing requests in the next queue."windows中在默认堆栈设置下,以及资源足够情况下,一个进程最多可创建2028线程.
      

  3.   

    线程数并非越多越好。理论上一个进程可创建的线程数 受到虚拟内存和线程栈大小的约束,msdn原文如下:
    The number of threads a process can create is limited by the available virtual memory. By default, every thread has one megabyte of stack space. Therefore, you can create at most 2028 threads. If you reduce the default stack size, you can create more threads. 
      

  4.   

    学习~~,顶。
    我前阵子刚好搞过相关的测试。我代码让启动2000个线程,但是实际上只能启动1986个左右的线程,但是当我修改了代码的部分内容后,可以起1998个。并且不同的机器跑同一个程序,线程数目也不一样。
    反正和每个线程工作需要的数据空间大小,机器的配置有关系。
    MSDN给出的就是理论上限阿。