测试我的笔记本能承受多少个线程创建

时间:2014-07-02 21:46:24   收藏:0   阅读:178
/***
*    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

 

测试我的笔记本能承受多少个线程创建,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!