From owner-freebsd-hackers Wed Apr 12 10:15:11 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from houston.matchlogic.com (houston.matchlogic.com [205.216.147.127]) by hub.freebsd.org (Postfix) with ESMTP id 6A47937B63F for ; Wed, 12 Apr 2000 10:14:56 -0700 (PDT) (envelope-from crandall@matchlogic.com) Received: by houston.matchlogic.com with Internet Mail Service (5.5.2650.21) id <2RMJ4RY1>; Wed, 12 Apr 2000 11:14:25 -0600 Message-ID: <5FE9B713CCCDD311A03400508B8B3013B24CAA@bdr-xcln.is.matchlogic.com> From: Charles Randall To: Ming Zhang , freebsd-hackers@freebsd.org Subject: RE: Multithread safe gethostbyname() ? Date: Wed, 12 Apr 2000 11:14:27 -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-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG adns should provide the functionality that you're looking for, http://www.chiark.greenend.org.uk/~ian/adns/ Charles -----Original Message----- From: Ming Zhang [mailto:ming@yahoo-inc.com] Sent: Tuesday, April 11, 2000 7:27 PM To: freebsd-hackers@freebsd.org Subject: Multithread safe gethostbyname() ? 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. I know the "struct hostent" is static in gethostbyname(), however it seems like the socket that is used to get the DNS info is static too. Attached it's the code I used for testing: ----- #include #include #include void vserv_request (void *d) { printf ("before byname\n"); gethostbyname ("test.exampledomain.com"); /* real host removed */ printf ("after byname\n"); } int create_request_thread (void) { pthread_t t_id; pthread_attr_t t_attr; int i = 0; pthread_attr_init (&t_attr); for (i = 0; i < 2; i++) { if (pthread_create(&t_id, &t_attr, vserv_request, (void *) NULL) != 0) return (-1); } return (0); } void main (void) { create_request_thread(); sleep (10000); /* I know sleep() is bad, just for the test */ } ------ both threads block after print "before byname". tested on both 3.4-stable and 4.0-stable (as of april 10th). any hints? Thanks To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message