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)
Asked
Active
Viewed 438 times
0
-
Are you using the default stack size? – Tim Post Mar 18 '14 at 14:00
-
3Out of curiosity, what for would you need 500 threads? – Christian Aichinger Mar 18 '14 at 14:06
-
Thanks for you replies.. I guess I'm using the default stack size.. How can I see the size of thread's stack of this process ? – user1047069 Mar 18 '14 at 14:13
-
1I can't think of a single good reason to want 500 threads on a desktop system with maybe 24 cores.. You're almost certainly solving the wrong problem – Voo Mar 18 '14 at 14:27
1 Answers
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