Is it possible by any means to change the limit on the number of pthreads a process can create ? Currently on my linux system I can create around 380 threads but I want to increase that to say as long as memory is available.
+1
A:
Look at this:
http://stackoverflow.com/questions/344203/maximum-number-of-threads-per-process-in-linux
And take a look at this as it might pertain to your question:
skwllsp
2009-12-22 16:00:16
`cat /proc/sys/kernel/threads-max` shows `16384`. But I cannot create more than 380 pthreads. I even tried putting a blank function as body of the threads.
Sukanto
2009-12-22 16:34:52
what error do you get?
skwllsp
2009-12-22 17:07:20
after 380 threads I get `EAGAIN` as return value of `pthread_create()`, which according to `pthread_create()` man page is "The system lacked the necessary resources to create another thread, or the system-imposed limit on the total number of threads in a process {PTHREAD_THREADS_MAX} would be exceeded."
Sukanto
2009-12-23 08:29:41
Are you testing 32-bit application? If so have you checked that when you create a 381 thread you have enough space for stack of the new thread?
skwllsp
2009-12-23 10:16:29
Or there might be a limit on virtual memory size for a process. You can see limits running `ulimit -a`
skwllsp
2009-12-23 11:01:48
virtual memory size limit is `unlimited`
Sukanto
2009-12-24 11:17:36
+2
A:
Your problem is that you have not called pthread_detach on the threads in question. This tells pthread that the resources associated with each thread will be released when the thread terminates. You have to call either pthread_join or pthread_release on all threads to release thread resources. That means that you also have to call pthread_detach in your pthread_join cancellation handlers or leak.