Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 12 Apr 2000 11:14:27 -0600
From:      Charles Randall <crandall@matchlogic.com>
To:        Ming Zhang <ming@yahoo-inc.com>, freebsd-hackers@freebsd.org
Subject:   RE: Multithread safe gethostbyname() ?
Message-ID:  <5FE9B713CCCDD311A03400508B8B3013B24CAA@bdr-xcln.is.matchlogic.com>

next in thread | raw e-mail | index | archive | help
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 <stdio.h>
#include <netdb.h>

#include <pthread.h>

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




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