From owner-freebsd-hackers Tue Apr 11 22:39:19 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from sharmas.dhs.org (c62443-a.frmt1.sfba.home.com [24.0.69.165]) by hub.freebsd.org (Postfix) with ESMTP id EFF6E37BBFA for ; Tue, 11 Apr 2000 22:39:17 -0700 (PDT) (envelope-from adsharma@sharmas.dhs.org) Received: (from adsharma@localhost) by sharmas.dhs.org (8.9.3/8.9.3) id WAA17491; Tue, 11 Apr 2000 22:38:58 -0700 Date: Tue, 11 Apr 2000 22:38:58 -0700 From: Arun Sharma Message-Id: <200004120538.WAA17491@sharmas.dhs.org> To: ming@yahoo-inc.com Cc: hackers@freebsd.org Subject: Re: Multithread safe gethostbyname() ? In-Reply-To: References: Reply-To: adsharma@sharmas.dhs.org Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG In muc.lists.freebsd.hackers, you wrote: > > Is there a MT-safe implementation of gethostbyname() in FreeBSD (3.4/4.0)? > > On Solaris there is gethostbyname_r(). Calling gethostbyname() with in > two threads cause both threads to block. You seem to be talking about two different things: 1. A reentrant function - two different threads can be in the same function simultaneously 2. A non blocking function. Reading the code in /usr/src/lib/libc{,_r}, it appears to me that, the FreeBSD implementation is not reentrant, and blocking. However, gethostbyname calls poll(2), which causes a reschedule to another runnable pthread, if any. In your case, both the threads are waiting for a DNS server response, so the thread scheduler doesn't have a thread to schedule. I think it'd be very useful to have a non-blocking DNS lookup API (one which exposes the underlying file descriptor) . Winsock has this. UNIX netscape 4.x would freeze half as often if this was done right. -Arun To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message