Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 11 Apr 2000 18:26:49 -0700 (PDT)
From:      Ming Zhang <ming@yahoo-inc.com>
To:        freebsd-hackers@freebsd.org
Subject:   Multithread safe gethostbyname() ?
Message-ID:  <Pine.BSF.4.10.10004111813310.81762-100000@pious.yahoo.com>

next in thread | raw e-mail | index | archive | help

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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.10.10004111813310.81762-100000>