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

  • From: alan@xxxxxxxxxxxxxx (Alan Ellis)
  • To: openbeos@xxxxxxxxxxxxx
  • Date: Tue, 10 Dec 2002 09:54:57 -0800

Ohh, yea, strtok would be a bear.

Some other functions may be fixable by making them block (with something
akin to a BLocker) to ensure thread safety.

Althouth it may be worth it to implement strtok so that it detects
multiple thread use and informs the user (via the debugger) that this is
a Bad Idea(tm).

Alan

On Tue, Dec 10, 2002 at 05:49:35PM +0100, Axel =?iso-8859-1?q?D=F6rfler ?= 
wrote:
> argent@xxxxxxxxxxxxxxxxxx wrote:
> > 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.
> 
> I really don't think that's the idea behind it.
> 
> > 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.
> 
> No, those functions *can't* be made thread-safe easily, just have a 
> look at their prototypes - they depend on global data. You would need 
> to put all global data/strings into fixed TLS slots which is certainly 
> not desirable.
> 
> Adios...
>    Axel.
> 
> 

Other related posts: