[openbeos] Re: POSIX thread safety, was: Re: Waiting and waiting

  • From: argent@xxxxxxxxxxxxxxxxxx
  • To: openbeos@xxxxxxxxxxxxx
  • Date: Tue, 10 Dec 2002 11:03:57 -0500

on Tue, Dec 10, 2002 at 11:38:13AM +0100, Axel =?iso-8859-1?q?D=F6rfler ?= was 
heard to have remarked:
> alan@xxxxxxxxxxxxxx (Alan Ellis) wrote:
> > I believe that the whole of the BeOS standard library was thread 
> > safe, and applications expect it to be.
> 
> No, just those functions which has to be.

I think there may be a confusion here between "reentrant" and
"thread-safe".  IIRC, reentrant functions produce the same result each
time they are called with identical arguments (e.g. sqrt(8)).  strtok
is an example of a non-reentrant function (look at it's definition to
see why).  Thread-safe functions are functions which can be called
from several threads simultaneously.  IMHO, all the BeOS library
functions should be thread-safe, although many may not be re-entrant.

> > Could you give me an example of a functiont that was not meant to be
> > thread safe? I would like to do some testing of your assumptions 
> > under the current BeOS (Dano actually_/
> 
> Well, that's all written down in the POSIX standard; example of non 
> thread-safe functions are (in no particular order): localtime(), 
> asctime(), ctime(), ttyname(), all random functions, strerror(), etc.
> OTOH they took a GPLd malloc()/free() - and they made it thread-safe, 
> because it was not.

Although the POSIX standard may declare that these functions need not
be thread-safe, an implementation where they are thread-safe would
certainly satisfy POSIX.  In BeOS, where threads are pervasive, I'd
argue that all of the standard library should be thread-safe.

-- 
Evan Knop <argent@xxxxxxxxxxx>      http://lore.dartmouth.edu/~argent/

"The trouble with doing something right the first time is that nobody 
appreciates how difficult it was."
- Walt West

Other related posts: