Subject: Re: getaddrinfo() vs. JVM
To: Nathan J. Williams <nathanw@wasabisystems.com>
From: Charles M. Hannum <abuse@spamalicious.com>
List: tech-userlevel
Date: 01/09/2005 20:45:40
On Sunday 09 January 2005 18:59, Nathan J. Williams wrote:
> jdolecek@NetBSD.org (Jaromir Dolecek) writes:
> > Charles M. Hannum wrote:
> > > > 2) Put a mutex around getservbyname() and/or getaddrinfo().  Is there
> > > > a way to do this in libc that will work both with and without
> > > > libpthread?
> > >
> > > I've done this.  See the following patches.
> >
> > Is the mutex around the calls to _r() functions really needed?
> > If they are marked _r, they should already be reentrant, shouldn't they?
>
> Charles's patch looks okay to me. The mutexes are protecting the
> (shared) data structure that the non-_r() functions are passing to the
> _r() functions The value returned isn't what's being protected.

Actually, I think it is a valid point that with just my change, one user of 
getaddrinfo() can corrupt the value returned to another user.  The mutex 
prevents the library from going off into lala land and crashing, but there is 
still a race in getaddrinfo().

The problem with Love's patch is that it will cause each thread using 
getaddrinfo() to open the file/whatever and keep its own state.  This sucks.