From owner-freebsd-questions Thu Jul 20 12:22: 9 2000 Delivered-To: freebsd-questions@freebsd.org Received: from crufty.research.bell-labs.com (crufty.research.bell-labs.com [204.178.16.49]) by hub.freebsd.org (Postfix) with SMTP id B3DC637C209 for ; Thu, 20 Jul 2000 12:22:02 -0700 (PDT) (envelope-from eran@aura.research.bell-labs.com) Received: from scummy.research.bell-labs.com ([135.104.2.10]) by crufty; Thu Jul 20 15:20:31 EDT 2000 Received: from aura.research.bell-labs.com ([135.104.46.10]) by scummy; Thu Jul 20 15:20:31 EDT 2000 Received: from localhost (eran@localhost) by aura.research.bell-labs.com (8.9.1/8.9.1) with SMTP id PAA17268; Thu, 20 Jul 2000 15:20:30 -0400 (EDT) Date: Thu, 20 Jul 2000 15:20:30 -0400 (EDT) From: Eran Gabber To: Tan Juay Kwang Cc: freebsd-questions@freebsd.org Subject: Re: pthreads on 4.0-STABLE In-Reply-To: <200007201347.JAA12961@zydeco.research.bell-labs.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > The first involves using pthread_create to generate several threads that > basically calls gethostbyname(3). I realize that I can only create 2 > threads at the most. Anything more, gethostbyname will never return and > thus the program will hang indefinitely. The same program runs fine on > Solaris 7 and RedHat 6.2 > > The second involves creating a thread that will block on a file I/O. > According to materials which I've read, a call to open a named pipe read > only will block until some other process opens it for writing. So the > scenario is that I've a main thread that uses pthread_create to spawn > another thread which will block on such an I/O, ie on the open(2) system > call. The anomaly is that the pthread_create does not return until that > I/O is completed. The call returns when I explicitly writes something to > it. The thread does more then just trying to open a file, but that is the > only point where it will block indefinitely. I tried the same thing on > RedHat 6.2 and it all works fine. I haven't try it on Solaris though. I found that the standard Pthreads library uses software threads, which tends to block the entire process (including all other threads) when one of the threads blocks. Although the source of the Pthreads library shows that other threads should be allowed to run when one of them blocks, in fact all threads blocks when one of them waits for file I/O. Try to use the linuxthreads package, which is available in FreeBSD 4.0. Linuxthreads is an alternate implementation of Pthreads, which supports true concurrency among threads. Linuxthreads employs the rfork() system call to create a new light-weight process for each thread. In this way, if one thread blocks, others can continue. Since linuxthreads is a different implementation of Pthreads with the same API, you can just relink your program with it and try again. It may solve your concurrent gethostbyname() problem and the dependency between phtread_create() and open()/read() that you reported. Eran To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message