Subject: Re: On multithreaded cclient

From: "Alex Shvedov" <[email-masked]>
Date: Fri, 11 Dec 1998 16:12:32 -0500

I'll tell you what is bad in tcp-unix's read/writes (my item 2; it takes
some time to re-create the problem) and in call-backs (my item 3; the
explanation is too long), but I became curious: is AIX the only fossil with
nonsafe gethostbyname or not (AIX people state that their version 4.3
complies with POSIX 1003.4a Draft 7)?

I immediately found out
(http://hoth.stsci.edu/man/man3N/endhostent.html#sect0) that Sun Solaris is
NOT safe also (they have gethostbyname_r as an alternative) and
(http://www.freebsd.org/cgi/man.cgi?query=gethostbyname&apropos=0&sektion=0&
manpath=FreeBSD+3.0-current&format=html) that current FreeBSD "use static
data storage".

Als? Hurray! The moment you learn that you're not the only one who feels
bad, you start feeling better.

Anyway, cclient is not safe for all systems - TIASNAQ.

You're right, fixing libc.a is a *real* solution, but...

The workaround I used was pretty dumb:
- forget about _r and call this thing before *any* spawning for all servers
you're going to use;
- remember the results (struct hostent), and
- fetch them by fake Gethostbyname (capital G) later when necessary.
The number of servers is normally small enough not to bother any more. And
my first purpose was just to find out what is not safe, after all.

>Quite frankly, if the cost of making c-client thread-safe on AIX (or any
other
>system) turns out to be breaking c-client for every system and application
>that doesn't use threads, it isn't going to happen.
Absolutely agree; you've done a great job already, and I don't expect you to
port cclient to a mechanical calculator.
Still, any predicate's range is limited to {TRUE, FALSE}; "cclient is safe
for all systems declared"=FALSE. Sorry.

>Any proposed thread solutions MUST be compatible with non-threading, and
furthermore MUST NOT
>introduce untoward burdens in the non-threading case.
That's exactly the way I see it. The changes I have (partly in mind, partly
in code) do not screw up single-threaded variant (tested).

---

From: Karsten Ballueder <[email-masked]>
Date: Mon, 14 Dec 1998 09:43:53 +0000 (GMT)

> my first purpose was just to find out what is not safe, after all.

Why didn't you use gethostname_r() ? Your approach can only work for
cases where you know all servers before starting the application which 
for a lot of applications won't be possible. My application is a
mail/news reader and there is no chance of knowing which
folders/servers the user will look at, before opening the first
stream. I think that solution is too limited. Is there any deeper
reason why you didn't just use the _r() variant?
-- 
 Karsten Ballüder http://www.phy.hw.ac.uk/~karsten/ mailto:[email-masked]
 Physics Department, Heriot-Watt University, Edinburgh, EH14 4AS, Scotland
                     Tel. +44-(0)-131-4513068  Fax. +44-(0)-131-4513136
           "In a world without fences, who needs Gates?"