/*** * 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