Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 02 Feb 2004 11:40:56 +0800
From:      David Xu <davidxu@freebsd.org>
To:        Daniel Eischen <eischen@vigrid.com>
Cc:        freebsd-threads@freebsd.org
Subject:   Re: pthread_create() blocks if maxthreads reached?
Message-ID:  <401DC6C8.6090006@freebsd.org>
In-Reply-To: <Pine.GSO.4.10.10402010956150.3021-100000@pcnet5.pcnet.com>
References:  <Pine.GSO.4.10.10402010956150.3021-100000@pcnet5.pcnet.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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.
>

You guys are better to not bet that Scheduler Activation can run large 
number of
threads, essential differences with libc_r is libpthread is kernel 
thread based, and
I don't think support of large number of threads is the design goal of 
SA,  it relies
on kernel. libpthread should query the sysctl to see if a new thread 
should be created,
and the sysctl value should be raised only. The benifit of libpthread is 
that it still can save
some resources and implement some POSIX semantics, for example, saving a 
kernel
thread resource if the thread sleeps in userland,  fast context switch ? 
and POSIX
SCHED_RR, SCHED_FIFO, Priority based scheduling...




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?401DC6C8.6090006>