http://d.puremagic.com/issues/show_bug.cgi?id=1478
Summary: Please use threadsafe functions in getHostByName
Product: D
Version: unspecified
Platform: PC
OS/Version: Linux
Status: NEW
Severity: normal
Priority: P2
Component: Phobos
AssignedTo: bugzilla digitalmars.com
ReportedBy: default_357-line yahoo.de
The following patch will change socket.d to use threadsafe functions for the
gethostbyname call on non-windows platforms. Not doing this can lead to all
sorts of ugly problems when using sockets in multi-threaded programs.
The patch is originally for gdc's socket.d, but should be equally applicable to
DMD.
diff socket.d.broken socket.d
487c487,497
< hostent* he = gethostbyname(toStringz(name));
---

http://d.puremagic.com/issues/show_bug.cgi?id=1478
------- Comment #2 from braddr puremagic.com 2007-10-14 16:40 -------
downs: I saw your comments in scrollback on irc. Two comments:
1) thanks.. you're right about the need to globally synchronize and not
per-class-instance synchronize. I've fixed that:
- synchronized he = gethostbyname(toStringz(name));
+ synchronized(this.classinfo) he = gethostbyname(toStringz(name));
2) Regarding the use of static if, that would only work if there was sufficient
configury mechanics to make sure that the _r versions were only included if
they exist. All static if can see is what's been declared, not what actually
is linkable. My main objection isn't really the declaration part of _r, but
the very wierd usage of needing to grow that buffer and iterate many times.
That'd likely end up more expensive than just synching.
Thanks for catching #1.
Later,
Brad
--