Chinaunix

标题: pthread_create问题 [打印本页]

作者: Zoelov    时间: 2013-10-29 15:49
标题: pthread_create问题
linux系统中对一个进程中创建多少个线程有限制吗?
我在测试一个程序时,想要创建2000个线程,但是在创建到一千多时就报错了 :pthread_create error:11,这是什么错误?什么原因造成的?
作者: linux_c_py_php    时间: 2013-10-29 16:16
       EAGAIN The  system  lacked  the  necessary  resources  to  create  another  thread, or the system-imposed limit on the total number of threads in a process
              {PTHREAD_THREADS_MAX} would be exceeded.
作者: Zoelov    时间: 2013-10-29 16:22
请问这段英文资料你是在哪里看到的?回复 2# linux_c_py_php


   
作者: Carl01Zhang    时间: 2013-10-29 22:26
#   define EAGAIN          11


int pthread_create( pthread_t * thread, void const *, unsigned (__stdcall * start_routine) (void*), void* arg )
{
    HANDLE h = (HANDLE)_beginthreadex( 0, 0, start_routine, arg, 0, 0 ) ;

    if( h != 0 )
    {
        *thread = h;
        return 0;
    }
    else
    {
        return EAGAIN;
    }
}



作者: Carl01Zhang    时间: 2013-10-29 22:27
或者man一下pthread_create
作者: timespace    时间: 2013-10-30 15:49
回复 1# Zoelov
如果线程栈是默认值,ulimit -s看下,一般为8MiB或10MiB,那么创建1000多线程,基本就8GiB以上,确认你的系统能否有这么大的内存地址空间


   




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2