On Fri, Jan 27, 2006 at 08:06:59AM -0500, David Zakar wrote:
> Is there a maximum number of threads I can spawn in a program using
> pthread_create() in Linux? I've noticed that once I exceed 300 or so, it
> appears to just refuse to create new threads.

Yes, there is.  IIRC, there are two limits:

        1. The resources available on the system (e.g. memory): you
        can't instantiate another thread if there's nowhere to put it.

        2. PTHREAD_THREADS_MAX (or somesuch: I'm going from memory
        so that string may have a typo or two in it), which defines
        the maximum number of threads.  It's defined in...umm...
        probably /usr/include/bits/local_lim.h and is likely set to
        8192 or 16384 or something like that -- so you _probably_
        shouldn't be bumping it at 300.

My recommendation is to check the return from pthread_create()
and see what it's set to -- perhaps that'll shed some light on
which limit you're bumping into.

-Rich

Reply via email to