0

I have about 500 threads that I want them to run simultaneously. I read that the default glibc allows only about 300 threads to run simultaneously. How did they got to this number? (I'm on 32 bit system)

user1047069
  • 935
  • 2
  • 13
  • 25

1 Answers1

3

The default stack size of a thread on linux is 10MB (or 8 on some). On a 32 bit linux, user space applications have 3GB of memory address space, some used for shared libraries, heap, the code, and other housekeeping, exhausting the address space at about 260 threads(2.6GB memory) is reasonable.

You can probably do with less space for the stack, so create threads with less stack space, e.g.

pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr, 1024*1000*2);

pthread_create(&tid, &attr, threadfunc, NULL);
nos
  • 223,662
  • 58
  • 417
  • 506