Received: from SOUTH-STATION-ANNEX.MIT.EDU by po7.MIT.EDU (5.61/4.7) id AA04924; Sun, 10 Dec 95 23:54:15 EST
Received: from LOLA-GRANOLA.MIT.EDU by MIT.EDU with SMTP
	id AA29495; Sun, 10 Dec 95 23:54:20 EST
Received: (from ghudson@localhost) by lola-granola.MIT.EDU (8.6.11/8.6.11) id XAA05915; Sun, 10 Dec 1995 23:54:21 -0500
Message-Id: <199512110454.XAA05915@lola-granola.MIT.EDU>
To: proven@MIT.EDU
Subject: Greg Hudson: Re: John Birrell: Re: pthreads (?) on NetBSD/Alpha? 
Date: Sun, 10 Dec 1995 23:54:20 EST
From: Greg Hudson <ghudson@MIT.EDU>


------- Forwarded Message

Received: from PACIFIC-CARRIER-ANNEX.MIT.EDU by po6.MIT.EDU (5.61/4.7) id AA29552; Sun, 10 Dec 95 23:53:54 EST
Received: from pain.lcs.mit.edu by MIT.EDU with SMTP
	id AA07674; Sun, 10 Dec 95 23:53:18 EST
Received: (from daemon@localhost) by pain.lcs.mit.edu (8.6.12/8.6.9) id XAA13915; Sun, 10 Dec 1995 23:30:39 -0500
Received: from lola-granola.MIT.EDU by pain.lcs.mit.edu (8.6.12/8.6.9) with ESMTP id XAA13864 for <netbsd-developers@netbsd.org>; Sun, 10 Dec 1995 23:19:12 -0500
Received: (from ghudson@localhost) by lola-granola.MIT.EDU (8.6.11/8.6.11) id XAA05767; Sun, 10 Dec 1995 23:19:09 -0500
Message-Id: <199512110419.XAA05767@lola-granola.MIT.EDU>
To: Chris G Demetriou <Chris_G_Demetriou@BALVENIE.PDL.CS.CMU.EDU>
Cc: netbsd-developers@NetBSD.ORG, cgd@BALVENIE.PDL.CS.CMU.EDU
Subject: Re: John Birrell: Re: pthreads (?) on NetBSD/Alpha? 
In-Reply-To: Your message of "Sun, 10 Dec 1995 22:28:22 EST."
             <561.818652502@BALVENIE.PDL.CS.CMU.EDU> 
Date: Sun, 10 Dec 1995 23:19:08 EST
From: Greg Hudson <ghudson@MIT.EDU>
Sender: owner-netbsd-developers@NetBSD.ORG
Precedence: first-class
X-Loop: netbsd-developers@NetBSD.ORG

Some notes:

> I got the following back, and am forwarding it with permission.  Any
> comments?  I've thought for a while that, as long as it doesn't cost
> much, making thread-safe versions of various libraries the _default_
> is a good idea...

The show-stopper here is getc().  POSIX.1c requires that getc() and
putc() be thread-safe (getc_unlocked() and putc_unlocked() being the
fast versions), which makes them a great deal slower than they are
now.  In particular, the following statement is not correct:

> I'm still trying to persuade J.T. to change NetBSD's errno
> implementation to call __error so that all libraries built with
> NetBSD can be linked into a threaded program.

(It may be good enough to have "everything but getc" work in most
libraries, but it still won't be POSIX.1c-compliant.  However, note
that making errno call __errno() will result in programs which won't
interoperate with older versions of libc; doing that for the sake of
an imperfect solution seems poor.)

Some of the statements Birrell made about Provenzano's pthreads
package are outdated (system calls returning -errno), wrong
(scheduling being spread out across libc functions), or indicative of
a lack of understanding of the design goals (the need for a
translation table between application and kernel file descriptors; the
requirement that much of libc be reimplemented to be thread-safe).

I think we should be familiar with the approaches Solaris and Linux
took here:

	* Solaris: has a binary shared libc which can be used with
	  both threaded and non-threaded programs, using weak
	  bindings.  This implies a certain speed hit (instead of
	  being elided completely, locks turn into calls to no-op
	  functions).

	  Outside of libc and some other system librarires, all code
	  linked into a threaded program has to be built with
	  -D_REENTRANT, to get both the thread-safe errno and the
	  thread-safe getc() and putc().  For the two reasons I've
	  outlined above (slower getc/putc and lack of
	  interoperability with old libcs), this requirement is not
	  easily avoidable.

	* Linux: borrowed Provenzano's schuleder (the "pthreads"
	  subdirectory of the package), and then modified the gnu libc
	  to be thread-safe (I suspect he hasn't successfully made all
	  of gnu libc thread-safe at this point), using weak bindings
	  so that the same binary can be used in threaded and non-threaded
	  programs.


------- End of Forwarded Message

