[talk] Is getaddrinfo thread-safe on OS X?

A. Jesse Jiryu Davis jesse at emptysquare.net
Sun Jan 3 10:57:13 EST 2016


Thanks for the pointers, with your help I'm making progress. I think I
found the source for Apple's getaddrinfo.

In Apple's Libinfo version 222.4.12, the man page says getaddrinfo isn't
thread-safe:

http://www.opensource.apple.com/source/Libinfo/Libinfo-222.4.12/lookup.subproj/getaddrinfo.3

And here's its source:

http://www.opensource.apple.com/source/Libinfo/Libinfo-222.4.12/lookup.subproj/getaddrinfo.c

Glancing at the source naïvely, I might see the data race: getaddrinfo
calls gai_lookupd, which reads and writes the global static variable
"gai_proc". I can't see what will go wrong as a result of the race, but it
sure LOOKS bad. =)

In the next release, version 278, the thread-safety warning is gone from
the man page:

http://www.opensource.apple.com/source/Libinfo/Libinfo-278/lookup.subproj/getaddrinfo.3

And getaddrinfo is largely rewritten:

http://www.opensource.apple.com/source/Libinfo/Libinfo-278/lookup.subproj/getaddrinfo.c

It calls a new function, "ds_getaddrinfo". But ds_getaddrinfo still
accesses the global static variable "gai_proc"; I wonder why this is
considered thread-safe now?

On Sun, Jan 3, 2016 at 12:14 AM, Siobhan Lynch <slynch2112 at me.com> wrote:

> OK… try and look at the revision histories of these three files:
>
>      *#include* *<sys/types.h>*
>      *#include* *<sys/socket.h>*
>      *#include* *<netdb.h>*
>
>
> *-Trish*
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nycbug.org/pipermail/talk/attachments/20160103/84f251a6/attachment.html>


More information about the talk mailing list