This is the mail archive of the mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: gethostbyname thread-safe?

On Mon, 10 Feb 2003, Ajay Nerurkar wrote:

> Is Cygwin's gethostbyname thread-safe? From a web search I got the
> impression that it wasn't and also that Cygwin does not have its
> reentrant version gethostbyname_r. So, what does one do?
> Ajay


Looking at the code (src/winsup/cygwin/,

964:#ifdef _MT_SAFE
965:#define hostent_buf  _reent_winsup ()->_hostent_buf
967:static struct hostent *hostent_buf = NULL;
970:/* exported as gethostbyname: standards? */
971:extern "C" struct hostent *
972:cygwin_gethostbyname (const char *name)

you can see that there is a provision for reentrancy.  However,
src/winsup/cygwin/acconfig.h #undef's _MT_SAFE.  OpenGroup's specification
says that "The gethostbyname() function need not be reentrant."
See <> for a good
discussion of gethostbyname() thread-safety issues.

So, your choices for the moment are:
1) build a thread-safe cygwin1.dll for your own use
2) make sure gethostbyname() is only called (and its result used/copied)
   by one thread at a time (using a mutex, for example)
3) implement gethostby{name,addr}_r() yourself and submit a patch

Hope this helps,
      |\      _,,,---,,_
ZZZzz /,`.-'`'    -.  ;-;;,_
     |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

Oh, boy, virtual memory! Now I'm gonna make myself a really *big* RAMdisk!
  -- /usr/games/fortune

Unsubscribe info:
Bug reporting:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]