From owner-freebsd-hackers Tue Apr 11 18:26:58 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from mrout1.yahoo.com (mrout1.yahoo.com [208.48.125.95]) by hub.freebsd.org (Postfix) with ESMTP id 6A1EA37BB46 for ; Tue, 11 Apr 2000 18:26:55 -0700 (PDT) (envelope-from ming@yahoo-inc.com) Received: from pious.yahoo.com (pious.yahoo.com [206.132.125.36]) by mrout1.yahoo.com (8.10.0/8.10.0/y.out) with ESMTP id e3C1Qoq93643 for ; Tue, 11 Apr 2000 18:26:50 -0700 (PDT) Received: from localhost (ming@localhost) by pious.yahoo.com (8.9.3/8.6.12) with ESMTP id SAA81987 for ; Tue, 11 Apr 2000 18:26:49 -0700 (PDT) X-Authentication-Warning: pious.yahoo.com: ming owned process doing -bs Date: Tue, 11 Apr 2000 18:26:49 -0700 (PDT) From: Ming Zhang X-Sender: ming@pious.yahoo.com To: freebsd-hackers@freebsd.org Subject: Multithread safe gethostbyname() ? Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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