From owner-freebsd-questions Fri Dec 3 0: 0:38 1999 Delivered-To: freebsd-questions@freebsd.org Received: from eagle.seed.net.tw (eagle.seed.net.tw [139.175.54.244]) by hub.freebsd.org (Postfix) with ESMTP id 009FB14BDB for ; Fri, 3 Dec 1999 00:00:33 -0800 (PST) (envelope-from chfeng@eagle.seed.net.tw) Received: (from chfeng@localhost) by eagle.seed.net.tw (8.9.2/8.9.1a) id PAA12319 for freebsd-questions@freebsd.org; Fri, 3 Dec 1999 15:59:10 +0800 (CST) Message-ID: <19991203155909.A11513@eagle.seed.net.tw> Date: Fri, 3 Dec 1999 15:59:09 +0800 From: Chih-hung Feng To: freebsd-questions@freebsd.org Subject: Is gethostbyname() multithread-safe? Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.93.2i X-Operating-System: SunOS 5.6 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Hi: I am writing a multithreaded proxy-like program on FreeBSD 3.x platform using POSIX thread library, and comming across a problem. When the program had been running for a while, it sometimes stopped responding anything. After further investigation, it turned out that all threads stopped at the same line of code: pserver = (struct hostenv *)gethostbyname(servername); Thus I am suspecting it was caused by something like resource locking or race condition inside gethostbyname() call. Tried to work around this I modified the code as: pthread_mutex_lock(&mutex); pserver = (struct hostent *)gethostbyname(servername); pthread_mutex_unlock(&mutex); I'm not sure this is the right way to do it. If gethostbyname() is MT-safe then it does no better except adding extra performance punishment. I'm not even sure the bug has been fixed (I made the modification today and the time is too short to prove the problem never comes back again). I will appreciate any kind of feedback. Please cc your reponse to my mailbox cause I'm not on this mailing list. Best Regards Chih-hung Feng Seednet, Taiwan chfeng@seed.net.tw To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message