pthread and max. number of threads
Hi, I want to find out the maximum number of threads allowed on my machine. I repeatedly created a thread in a loop, and the result of running this small program is: thread 0 created. ... ... pthread_create error on thread 255, error code = 11 Does this error code indicate that the maximum number of threads has been reached? How can I increase this maximum number? Does it involve ulimit? Or perhaps I need to modify the _POSIX_THREAD_THREADS_MAX and PTHREAD_THREADS_MAX definitions in /usr/include/bits/local_lim.h? Currently, they're 64 and 16384 respectively. -- -- Verdi March --
Btw, the code: #include <stdlib.h> #include <stdio.h> #include <errno.h> #include <pthread.h> void* do_one_thing(void* arg); int main(void) { pthread_t t[500]; int i = 0; for (i = 0; i < 499; i++) { int code = pthread_create(&(t[i]), NULL, do_one_thing, NULL); if (code != 0) { printf("pthread_create error on thread %d, error code = %d\n", i, code); exit(1); } printf("thread %d created.\n", i); } for (i = 0; i < 499; i++) { if (!pthread_join(t[i], NULL)) { printf("pthread_join error on thread %d\n", i+1); } } return 0; } void* do_one_thing(void* arg) { return NULL; } -- -- Verdi March --
No one :( ? I've googled around, and found no definitive solutions. Some refer to kernel 2.2 (increase NR_TASK and recompile), whereas for 2.4 this should not necessary. Others refer to increas PTHREAD_THREADS_MAX in local_lim.h and recompiling glibc. However, in suse glibc, this number is already 16384. Oh, and my /proc/sys/kernel/threads-max by default is 3967. But the number of thread I can created is only 256. -- -- Verdi March --
By default, the installed glibc is glibc-2.3.2-9.i686 (on P3 and P4). Using this version, I managed to create only up to 256 threads on both machines (both have 256MB RAM). But by switching to glibc-2.3.6-6.i586, I managed to create up to 1533 threads. -- -- Verdi March --
participants (1)
-
Verdi March