Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 21 Jul 2000 12:21:26 -0600
From:      Charles Randall <crandall@matchlogic.com>
To:        Tan Juay Kwang <tanjk@i-dns.net>, "Richard Seaman, Jr." <dick@tar.com>
Cc:        freebsd-questions@FreeBSD.ORG
Subject:   RE: pthreads on 4.0-STABLE
Message-ID:  <5FE9B713CCCDD311A03400508B8B301301C783D5@bdr-xcln.is.matchlogic.com>

next in thread | raw e-mail | index | archive | help
Look at using adns for thread-safe asynchronous DNS lookups,

http://www.chiark.greenend.org.uk/~ian/adns/

Charles

-----Original Message-----
From: Tan Juay Kwang [mailto:tanjk@i-dns.net]
Sent: Friday, July 21, 2000 10:39 AM
To: Richard Seaman, Jr.
Cc: freebsd-questions@FreeBSD.ORG
Subject: RE: pthreads on 4.0-STABLE


>
> AFAIK, FreeBSD's implementation of gethostbyname is not thread safe,
> though I haven't studied it in detail, so its possible I'm wrong.
> What happens if you wrap your calls to gethostbyname() with a mutex?
> Does it work then?
>

I'm not tried this approach but even if it does work, it will means that
my gethostbyname are done serially, which is not what I really want.

> In general, the specs I've seen (eg SUSv2) also stipulate that
> even if gethostbyname is "thread safe" it can return a pointer
> to a static data structure.  So, if you're going to use it in
> multiple threads, and you want to be portable, you really need
> to wrap gethostbyname() in a mutex even if its "thread safe" so
> you use the returned pointer before releasing the mutex.  Otherwise
> some other thread can stomp on the static structure before you
> use it.
>

I see. Well, I guess the best thing I can do is to send out DNS packet
myself then, without going through kernel services.

> Ideally, a threads package will provide gethostbyname_r, where you
> pass a buffer for the result so you can avoid having to wrap the
> call in a mutex.  Unfortunately, I don't see this call in the
> FreeBSD user threads package.  Such a call does exist in linuxthreads
> (as well as the FreeBSD linuxthreads port --
>  see /usr/ports/devel/linuxthreads).
>
>

Right, will definitely check out the port, thanks.

Best regards,
Juay Kwang


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?5FE9B713CCCDD311A03400508B8B301301C783D5>