RE: [suse-programming-e] pthread and max. number of threads
The maximum number of pthreads per user is 1024. This is set in the pthread libraries. The maximum number of pthreads for the entire system can be set in proc, but it's unlikely you'd need to change this value. The way they seem to get that number is that pthread's stack space is allocated on the heap and each thread takes 2 megs of heap by default. Linux has a maximum of 2 gig heap per user, so 2meg @ 1024 give you 2 gigs of heap. If you need to increase the maximum number of threads per user, you'll need to recompile the pthread library and decrease the amount of heap per thread. This could have system wide effects, so I don't recommend it except for finely tuned application servers. It's better to re-architect your software around it or move to a different environment. Check out : http://www.jlinux.org/server.html http://www.xde.net/forum/xq/forum.56/thread.24291/qx/thread.htm Jonathan Paul Cowherd Linux and Java Administrator Genscape, Inc. Email: jonathan.cowherd@genscape.com Office: (502) 583-3730 Mobile: (502) 314-0444
-----Original Message----- From: Verdi March [mailto:cincaipatron@gmx.net] Sent: Monday, July 28, 2003 2:56 AM To: suse-programming-e@suse.com Subject: [suse-programming-e] 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 --
-- To unsubscribe, email: suse-programming-e-unsubscribe@suse.com For additional commands, email: suse-programming-e-help@suse.com Archives can be found at: http://lists.suse.com/archive/suse-> programming-e
On Tuesday 29 July 2003 22:57, Jonathan Cowherd wrote:
If you need to increase the maximum number of threads per user, you'll need to recompile the pthread library and decrease the amount of heap per thread.
Thanks, I missed this part. I thought that since suse has increased PTHREAD_THREADS_MAX it also decreased STACK_SIZE. Turns out to be wrong though...
It's better to re-architect your software around it or move to a different environment.
About redesigning the software, it's kinda difficult. I'm working on a simulation, it's built using another a simulation library (written in C) that utilizes thread. So it's the library that do all the thread-thing (yes, the library is GPL, but the purpose of using it is to avoid writing my application from scratch ;-). Later on, I need to do large simulation, which will generate lots lots of threads. -- -- Verdi March --
On Wed, 30 Jul 2003 11:01:33 +0800
Verdi March
About redesigning the software, it's kinda difficult. I'm working on a simulation, it's built using another a simulation library (written in C) that utilizes thread. So it's the library that do all the thread-thing(yes, the library is GPL, but the purpose of using it is to avoid writing my application from scratch ;-). Later on, I need to do large simulation, which will generate lots lots of threads. You can set the stack size with pthread_attr_setstacksize, but that should never be less than PTHREAD_STACK_SIZE. I think you are between the preverbial rock and a hard place. You can make the appropriate changes, but you still risk running out of resources. I would like to see Linux start using mmap to allocate thread control blocks and stacks rather than the heap, but that may require some extensive changes to the kernel.
--
Jerry Feldman
participants (3)
-
Jerry Feldman
-
Jonathan Cowherd
-
Verdi March