pthread_create() blocks if maxthreads reached?

Daniel Eischen eischen at vigrid.com
Sun Feb 1 08:57:52 PST 2004


On Sun, 1 Feb 2004, Alex Keahan wrote:

> On Sunday 01 Feb 2004 5:06 pm, Daniel Eischen wrote:
> >
> > 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)

That isn't true.  The main thread can exit and other threads
will continue to run and keep the application alive.  The
threads library can't guess as to which thread is "special".
It could be that the main thread creates only one thread,
and this thread is the thread that creates all the other
threads.  The main thread could block in the kernel as
well.

The threads library can't guess at what your applications
really want.  You guys are looking at the application and
can infer what behavior you'd like to see, but the threads
library isn't artifically intelligent.

-- 
Dan Eischen



More information about the freebsd-threads mailing list