You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Craig Rodrigues <ro...@crodrigues.org> on 2004/07/02 21:43:54 UTC

FreeBSD APR patch for threads

Hi,

I maintain the port for apr in the FreeBSD ports collection.


The latest version of FreeBSD's implementation of threads is *MUCH*
more stable than in earlier versions of FreeBSD.  To compile a program
for threads, all you need to do is link with -lpthread.  -D_REENTRANT
and -D_THREAD_SAFE are no longer needed and have been entirely removed
from FreeBSD header files.

I have been maintaining a variation of this patch which I would
like to submit back to the APR repository.

This patch basically does the following:
 - for the latest versions of FreeBSD, puts in the correct flags for
   linking in threads
 - for older versions of FreeBSD, i.e FreeBSD 4.x, disables threads by 
   default (which is what APR does right now)   

I've been testing this patch for some time now.
Would it be possible to go in for APR 1.0?



Index: apr_hints.m4
===================================================================
RCS file: /home/cvspublic/apr/build/apr_hints.m4,v
retrieving revision 1.63
diff -u -r1.63 apr_hints.m4
--- apr_hints.m4	14 Jun 2004 21:16:40 -0000	1.63
+++ apr_hints.m4	2 Jul 2004 19:42:55 -0000
@@ -136,14 +136,15 @@
 	APR_ADDTO(CPPFLAGS, [-DNETBSD])
 	;;
     *-freebsd*)
-	case $host in
-	    *freebsd[[2345]]*)
-		APR_ADDTO(CFLAGS, [-funsigned-char])
-		;;
-	esac
-	APR_SETIFNULL(enable_threads, [no])
         APR_SETIFNULL(apr_lock_method, [USE_FLOCK_SERIALIZE])
-	APR_ADDTO(CPPFLAGS, [-D_REENTRANT -D_THREAD_SAFE])
+	os_version=`sysctl -n kern.osreldate`
+	if test $os_version -ge "502102"; then
+		apr_cv_pthreads_cflags="none"
+		apr_cv_pthreads_lib="-lpthread"
+	else
+		apr_cv_pthreads_cflags="-D_THREAD_SAFE -D_REENTRANT"
+		APR_SETIFNULL(enable_threads, [no])
+	fi
 	;;
     *-next-nextstep*)
 	APR_SETIFNULL(CFLAGS, [-O])



-- 
Craig Rodrigues        
http://crodrigues.org
rodrigc@crodrigues.org

Re: FreeBSD APR patch for threads

Posted by Justin Erenkrantz <ju...@erenkrantz.com>.
--On Friday, July 2, 2004 3:43 PM -0400 Craig Rodrigues 
<ro...@crodrigues.org> wrote:

> I have been maintaining a variation of this patch which I would
> like to submit back to the APR repository.
>
> This patch basically does the following:
>  - for the latest versions of FreeBSD, puts in the correct flags for
>    linking in threads
>  - for older versions of FreeBSD, i.e FreeBSD 4.x, disables threads by
>    default (which is what APR does right now)
>
> I've been testing this patch for some time now.
> Would it be possible to go in for APR 1.0?

Thanks!  Committed.  -- justin

Re: FreeBSD APR patch for threads

Posted by Craig Rodrigues <ro...@crodrigues.org>.
On Sat, Jul 03, 2004 at 03:24:15AM -0700, Paul Querna wrote:
> Disabling threads by default in APR because of a broken model in HTTPd
> does not make any sense.  When we compile without threads, we also
> disable things like apr_reslist.  Personally, I have used apr_relist
> +prefork MPM on FreeBSD 4.x/5.x without any problems.
> 
> Why do you want to disable thread support by default?  Is there any
> reason besides problems with the Worker MPM?

Worker MPM is definitely broken on FreeBSD 4.x.  I've verified that.

The only reason I chose to disable thread support on earlier
versions of FreeBSD is because that is the default behavior of the
APR configure scripts now.  I thought it would be less controversial
to keep the existing behavior for earlier versions of FreeBSD.

-- 
Craig Rodrigues        
http://crodrigues.org
rodrigc@crodrigues.org

Re: FreeBSD APR patch for threads

Posted by Justin Erenkrantz <ju...@erenkrantz.com>.
--On Saturday, July 3, 2004 3:24 AM -0700 Paul Querna <ch...@force-elite.com> 
wrote:

> I do not believe there is any reason to disable thread support in APR
> itself.  Even on 4.x where the native threading is horrible, and the
> Worker MPM is broken.

Yes, there is.  Lots of weird and subtle things break when threading is 
enabled on FreeBSD.  Besides the well-documented worker MPM problem, 
Subversion fails to display certain important prompts when threading is 
enabled - which make Subversion inoperable with threads enabled.  (Disabling 
threads on FreeBSD makes the prompts appear.)

We've hit this with minotaur.apache.org which is FreeBSD 4.10 - it made it 
impossible for us to commit on our own SVN server!  Since libxml2 at one point 
used threads which was used by neon which is used by Subversion, Subversion 
implicitly enabled threads and circumvented APR's disabling of threads. 
(FWIW, libxml2 has since been configured to not use threads in FreeBSD ports.)

So, this just isn't httpd or a flaw in the worker MPM model - the bugs in the 
threading library have been seen even without programs explicitly using 
threads.  The best we can tell for the Subversion bug is that the scheduler 
gets confused and eats an important fd that should be displaying a prompt.

If it works for you, good - but *I* absolutely don't want to track down bugs 
in the FreeBSD threading code - I've seen enough not to trust that code at 
*all*.  FreeBSD 4.x's crappy gdb doesn't help track down problems either - at 
least 5.x sort of supports current gdb's - but that work is continuing in 
-CURRENT.  Besides not supporting threads properly, gdb's support for FreeBSD 
4.x shared libraries is utter junk.  -- justin

Re: FreeBSD APR patch for threads

Posted by Paul Querna <ch...@force-elite.com>.
On Fri, 2004-07-02 at 15:43 -0400, Craig Rodrigues wrote:
> [..snip..]
> This patch basically does the following:
>  - for the latest versions of FreeBSD, puts in the correct flags for
>    linking in threads
>  - for older versions of FreeBSD, i.e FreeBSD 4.x, disables threads by 
>    default (which is what APR does right now)   

I do not believe there is any reason to disable thread support in APR
itself.  Even on 4.x where the native threading is horrible, and the
Worker MPM is broken.

Disabling threads by default in APR because of a broken model in HTTPd
does not make any sense.  When we compile without threads, we also
disable things like apr_reslist.  Personally, I have used apr_relist
+prefork MPM on FreeBSD 4.x/5.x without any problems.

Why do you want to disable thread support by default?  Is there any
reason besides problems with the Worker MPM?

-Paul Querna


Re: FreeBSD APR patch for threads

Posted by Craig Rodrigues <ro...@crodrigues.org>.
On Sat, Jul 03, 2004 at 10:44:44AM -0700, Justin Erenkrantz wrote:
> Right - I understand that.  But, my question is what are the semantics for 
> kern.osreldate?  If/when 5.2.2 comes out, it won't be greater than 502102, 
> correct?  -- justin

See:
http://www.freebsd.org/doc/en_US.ISO8859-1/books/porters-handbook/freebsd-versions.html

-- 
Craig Rodrigues        
http://crodrigues.org
rodrigc@crodrigues.org

Re: FreeBSD APR patch for threads

Posted by Justin Erenkrantz <ju...@erenkrantz.com>.
--On Saturday, July 3, 2004 9:36 AM -0400 Craig Rodrigues 
<ro...@crodrigues.org> wrote:

> On Fri, Jul 02, 2004 at 06:24:38PM -0700, Justin Erenkrantz wrote:
>> report '502010', which is less than '502102' - so it would prevent them
>
> libkse was renamed to libpthread in 502102.  So this patch
> would keep the status quo and disable threads under 5.2.1.

Right - I understand that.  But, my question is what are the semantics for 
kern.osreldate?  If/when 5.2.2 comes out, it won't be greater than 502102, 
correct?  -- justin

Re: FreeBSD APR patch for threads

Posted by Craig Rodrigues <ro...@crodrigues.org>.
On Fri, Jul 02, 2004 at 06:24:38PM -0700, Justin Erenkrantz wrote:
> report '502010', which is less than '502102' - so it would prevent them 

libkse was renamed to libpthread in 502102.  So this patch
would keep the status quo and disable threads under 5.2.1.

-- 
Craig Rodrigues        
http://crodrigues.org
rodrigc@crodrigues.org

Re: FreeBSD APR patch for threads

Posted by Justin Erenkrantz <ju...@erenkrantz.com>.
--On Friday, July 2, 2004 1:22 PM -0700 Aaron Bannert <aa...@clove.org> 
wrote:

>> This patch basically does the following:
>>  - for the latest versions of FreeBSD, puts in the correct flags for
>>    linking in threads
>>  - for older versions of FreeBSD, i.e FreeBSD 4.x, disables threads by
>>    default (which is what APR does right now)
>
> I'm +1 for this patch in concept, but I don't have a FreeBSD machine
> with an osreldate recent enough to test this patch.

As noted in httpd's STATUS, FreeBSD 5.2 isn't sufficient as the default 
thread library there (libc_r) still breaks with httpd's worker.  I've also 
seen breakage with Subversion if threads are enabled: the commit for SSL 
cert prompts will not display correctly.  If you play with libmap.conf to 
use libkse, httpd will serve pages correctly with 5.2.  The good news is 
that 5.3 (and -CURRENT now, I believe) will switch to libkse by default...

That said, I'm not quite clear what the semantics of kern.osreldate are - 
will that block off any 5.2.x (i.e. 5.2.2 if that is released) and only 
allow current -CURRENT and eventually 5.3 and beyond?  My 5.2.1 boxes 
report '502010', which is less than '502102' - so it would prevent them 
from enabling threads.  I just want to make sure that it doesn't trigger on 
a 5.2.2 which, AIUI, will still use libc_r.  If it does block 5.2.x, then 
this patch gets +1.  Regardless, this is not something that must go into 
APR 1.0 - we can commit it after 1.0 (which should have been today!).  -- 
justin

Re: FreeBSD APR patch for threads

Posted by Aaron Bannert <aa...@clove.org>.
On Jul 2, 2004, at 12:43 PM, Craig Rodrigues wrote:
> I maintain the port for apr in the FreeBSD ports collection.
>
>
> The latest version of FreeBSD's implementation of threads is *MUCH*
> more stable than in earlier versions of FreeBSD.  To compile a program
> for threads, all you need to do is link with -lpthread.  -D_REENTRANT
> and -D_THREAD_SAFE are no longer needed and have been entirely removed
> from FreeBSD header files.

This is great news!

> I have been maintaining a variation of this patch which I would
> like to submit back to the APR repository.
>
> This patch basically does the following:
>  - for the latest versions of FreeBSD, puts in the correct flags for
>    linking in threads
>  - for older versions of FreeBSD, i.e FreeBSD 4.x, disables threads by
>    default (which is what APR does right now)

I'm +1 for this patch in concept, but I don't have a FreeBSD machine
with an osreldate recent enough to test this patch.

> I've been testing this patch for some time now.
> Would it be possible to go in for APR 1.0?

Well, let's get it into HEAD and get some feedback on it first.

-aaron