why pthread_create with a detached attribute won't work correctly

Yuehua Liu yhua_liu at yahoo.com
Wed Oct 10 06:55:53 EDT 2001


Hi Everyone,

Here is a time-critical problem for your kind help.

I am developing a web server application and use
Pthreads to handle every client's request.  (My
machine is a SUN ultra 10 SPARC. The application will
be run on SUN E450 SPARC or higher later.) When I test
the program with 40 clients loaded concurrently (one
user thread created per client), the system returns
error (EAGAIN) in the pthread_create routine after the
application have created about 25 user threads (they
are set with detached attribute and a reasonable stack
size). Even more, in subsequent similar tests the
number of threads that can be created drops to about
half of the previous number, till no user thread can
be created any more. Another case is that
pthread_create has only one thirds of throughput if I
test the program with a low load on the machine. In
both cases the average time for handling a client's
request is about 300~500milliseconds, initially within
my plan. But the number of user threads that can be
created is hardly down below my hope. Actually I want
the application to process consistently and stably
about 100 clients concurrently (thus creating about
100 user threads concurrently).

After I change those user threads to a joinable
attribute and create an additional thread (using a
loop) to dynamically wait for each user thread to
terminate, every pthread_create produces its user
thread while the average processing time drops to
about 8000 milliseconds. Actually, I need not at all
to wait for a user thread to terminate. I only want
them to terminate automatically and to free resources
for other pending threads. But a detached thread just
won't work correctly as described in the first
paragraph.

I have fixed most of the significant memory leaks
already. The problem seems to arise from consuming
away system resources, or reaching the system's limit
of creating threads within a process, or other
reasons. Does it seem that a user thread created with
a detached attribute has not release its system
resources? Are there any trade-offs between a detached
thread and joinable thread? Is there anyway to
configure the critical system limits on an application
like ours for a SUN ultra 10 SPARC machine and alike?
Are there any guidelines on how to fix these problems?

Thanks a lot and with regards.

Yuehua







__________________________________________________
Do You Yahoo!?
Make a great connection at Yahoo! Personals.
http://personals.yahoo.com



More information about the sunmanagers mailing list