From Bugzilla Helper: User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030922 Epiphany/1.0.1 Description of problem: There seems to be a limit of 304 pthreads that can be created for a single process. The problem also occurs on 2.1 with a limit of 254 threads. This can be demonstrated with the following code: [dturner@localhost tmp]$ cat MaxThread.c #include <stdio.h> #include <stdlib.h> #include <pthread.h> #include <unistd.h> #include <sys/types.h> void *threadfunc(void *); main() { int i, t; pthread_t thread; printf("Starting threads\n"); for (i=0; i< 2000; i++) { t = pthread_create(&thread, NULL, threadfunc, NULL); if (t == 0) printf("created thread %d\n", i); else { printf("Unable to create thread. Failed at %d\n", i); break; } } sleep(1); printf("Any key to exit\n"); getchar(); exit(0); } void *threadfunc(void * arg) { // sleep for a while sleep(10); } Version-Release number of selected component (if applicable): How reproducible: Always Steps to Reproduce: 1. gcc -lpthread -D_REENTRANT -o MaxThread MaxThread.c 2. ./MaxThread Actual Results: [dturner@localhost tmp]$ ./MaxThread Starting threads created thread 0 ... created thread 303 created thread 204 Unable to create thread. Failed at 205 Any key to exit Additional info: [david@localhost tmp]$ ulimit unlimited [david@localhost tmp]$ cat /proc/sys/kernel/threads-max 1000000 [dturner@localhost tmp]$ cat /proc/meminfo total: used: free: shared: buffers: cached: Mem: 393404416 382902272 10502144 0 19243008 237506560 Swap: 1076051968 5435392 1070616576 MemTotal: 384184 kB MemFree: 10256 kB MemShared: 0 kB Buffers: 18792 kB Cached: 228304 kB SwapCached: 3636 kB Active: 242104 kB ActiveAnon: 111444 kB ActiveCache: 130660 kB Inact_dirty: 0 kB Inact_laundry: 106696 kB Inact_clean: 5084 kB Inact_target: 70776 kB HighTotal: 0 kB HighFree: 0 kB LowTotal: 384184 kB LowFree: 10256 kB SwapTotal: 1050832 kB SwapFree: 1045524 kB HugePages_Total: 0 HugePages_Free: 0 Hugepagesize: 4096 kB
More interesting is what ulimit -s shows. If it prints unlimited, then default thread stack size is 8MB, otherwise it is the specified value (unless pthread_attr_setstacksize etc. are used). With 8MB thread stacks you run out of virtual memory really soon.
That'll be it then. I have reduced the stack size and demonstrated that this is not a bug. Thank you.