Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 20 Jul 2000 15:20:30 -0400 (EDT)
From:      Eran Gabber <eran@research.bell-labs.com>
To:        Tan Juay Kwang <tanjk@i-dns.net>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: pthreads on 4.0-STABLE
Message-ID:  <Pine.GSO.3.96.1000720151822.10644k-100000@aura.research.bell-labs.com>
In-Reply-To: <200007201347.JAA12961@zydeco.research.bell-labs.com>

next in thread | previous in thread | raw e-mail | index | archive | help
> 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




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