From owner-freebsd-questions Fri Jul 21 11:21:36 2000 Delivered-To: freebsd-questions@freebsd.org Received: from houston.matchlogic.com (houston.matchlogic.com [205.216.147.127]) by hub.freebsd.org (Postfix) with ESMTP id DF66937BDE3 for ; Fri, 21 Jul 2000 11:21:30 -0700 (PDT) (envelope-from crandall@matchlogic.com) Received: by houston.matchlogic.com with Internet Mail Service (5.5.2650.21) id ; Fri, 21 Jul 2000 12:21:28 -0600 Message-ID: <5FE9B713CCCDD311A03400508B8B301301C783D5@bdr-xcln.is.matchlogic.com> From: Charles Randall To: Tan Juay Kwang , "Richard Seaman, Jr." Cc: freebsd-questions@FreeBSD.ORG Subject: RE: pthreads on 4.0-STABLE Date: Fri, 21 Jul 2000 12:21:26 -0600 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2650.21) Content-Type: text/plain; charset="iso-8859-1" Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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