pthread_create() blocks if maxthreads reached?

Alex Keahan ak at freenet.co.uk
Sun Feb 1 08:22:57 PST 2004


On Sunday 01 Feb 2004 5:06 pm, Daniel Eischen wrote:
> On Sat, 31 Jan 2004, Julian Elischer wrote:
> > On Sun, 1 Feb 2004, Craig Rodrigues wrote:
>
>   [ ... ]
>
> > > If I link this program with -lthr or -lc_r, the
> > > program will terminate.
> >
> > Successfully?
> > that's interesting.. libthr should theoretically b elimited to about
> > 8000 threads.. (on x86).
> >
> > > If I link with -lpthread, the program seems to
> > > block in the pthread_create() call, instead of
> > > returning EAGAIN (to indicate that a new thread cannot
> > > be created due to hitting some system limit).
> >
> > is that what you expected?
>
> The threads are created and scheduled in userland (the default
> is process scope threads, so there is no syscall needed to
> create these threads).  You probably even created more than
> `sysctl kern.threads.max_threads_per_proc` but when the
> main thread got swapped out (due to quantum expiration)
> and the other threads were scheduled, they blocked in
> the kernel and _then_ the system resource limit was hit.
> There were no threads left for upcalls, and even if there
> was one left for an upcall, there's no guarantee that the
> library can figure out which thread to resume so that
> your application gets an appropriate error return.

Perhaps the main thread should be treated specially in this
regard?   It is already special with respect to other threads in
that it keeps them on life support (if the main thread exits, the
entire process disappears)

AK



More information about the freebsd-threads mailing list