/***
*    test how many threads can be created in x86 32 system
*   
*         ubuntu 13.0
*
*
*************************************************************/
#include <stdio.h>
#include <pthread.h>

static void test(void *arg);

int main()
{
    pthread_t p;
    pthread_attr_t pattr;
    pthread_attr_init(&pattr);
    pthread_attr_setdetachstate(&pattr, PTHREAD_CREATE_DETACHED);
    int count =0;

    while(pthread_create(&p, &pattr, test, NULL) == 0)
    {
        count++;
    }

    printf("only %d threads can be created\n", count);
    return 0;       
}

static void test(void *arg)
{
    while(1)
    {
        //do nothing
    }
}

结果:

only 382 threads can be created

...

 

相关文章:

  • 2021-05-22
  • 2021-05-01
  • 2022-12-23
  • 2022-12-23
  • 2021-05-28
  • 2022-12-23
  • 2021-10-09
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-09
  • 2021-12-27
  • 2021-10-29
相关资源
相似解决方案