Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 22 Jan 1999 12:19:49 -0600
From:      "Richard Seaman, Jr." <dick@tar.com>
To:        "Kurt D. Zeilenga" <Kurt@OpenLDAP.Org>
Cc:        freebsd-current@FreeBSD.ORG
Subject:   Re: -D_REENTRANT (Was: Using LinuxThreads)
Message-ID:  <19990122121949.I92540@tar.com>
In-Reply-To: <36A8BA23.8AE3B430@OpenLDAP.Org>; from Kurt D. Zeilenga on Fri, Jan 22, 1999 at 09:49:23AM -0800
References:  <Pine.BSF.4.05.9901182203500.11971-100000@janus.syracuse.net> <19990119024539.A88383@top.worldcontrol.com> <19990119140613.B826@shale.csir.co.za> <19990119091151.F600@tar.com> <19990121181228.A98581@shale.csir.co.za> <3.0.5.32.19990121114214.00958c30@localhost> <19990121143940.D5495@tar.com> <36A7A395.29B3E8A7@OpenLDAP.Org> <19990122114153.H92540@tar.com> <36A8BA23.8AE3B430@OpenLDAP.Org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Jan 22, 1999 at 09:49:23AM -0800, Kurt D. Zeilenga wrote:
> "Richard Seaman, Jr." wrote:
> > _THREAD_SAFE is only used in stdio.h.  Looking at what's there, it could
> > be rewritten to eliminate _THREAD_SAFE entirely, at a (very slight)
> > performance penalty.  You'd have to check __isthreaded (could be done
> > once, instead of twice, as in the code now) each time you call one
> > of the functions defined within the _THREAD_SAFE switch.  All
> > _THREAD_SAFE does is let you avoid checking __isthreaded when you're
> > not threaded.
> 
> So, if I want to produce a library which can be safely used by both
> threaded and non-threaded applications I should NOT define -D_THREAD_SAFE
> such that __isthreaded is always checked by the library.

I guess I was a little unclear.  

1) I think you would have to rewrite a little bit of the header to
use the __isthreaded test on a couple of more functions.

2) If you always define -D_THREAD_SAFE, __isthreaded will be
checked whether you're threaded or not.  If you're not threaded,
__isthreaded should be false and you avoid the file locking
code.  If you're threaded, __isthreaded should be true and you
get the file locking (if you're linked with a library that
has actualy file locking code to override the libc file locking
stub functions -- libc_r does this for you, you need something
like a pthreads library linked in for libc).

You could also just eliminate _THREAD_SAFE entirely by letting 
__isthreaded get checked on each relevant call.

3) If you're linking with FreeBSD user threads, you still have the
problem that user threads needs libc_r and not libc, while everything
else (no threads, or kernel threads) needs libc.  The _THREAD_SAFE
switch doesn't affect whether you link with libc or libc_r.

As mentioned before, libc_r could be rewritten to look like a 
"normal" libpthread addon library, ie. it wouldn't duplicate
libc, but it would require some work.

4) There are portions of libc that are only thread safe when they
are compiled as part of libc_r (almost all of libc gets rolled into
libc_r).  This can be fixed.  Indeed, I have patches that do this,
but they need some testing.

-- 
Richard Seamman, Jr.          email: dick@tar.com
5182 N. Maple Lane            phone: 414-367-5450
Chenequa WI 53058             fax:   414-367-5852

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message



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