This is the mail archive of the
cygwin
mailing list for the Cygwin project.
pthreads leaks handles and threads when threads use sockets
- From: "Mark Pizzolato" <list-cygwin at subscriptions dot pizzolato dot net>
- To: <cygwin at cygwin dot com>
- Date: Fri, 28 Jan 2005 09:09:31 -0800
- Subject: pthreads leaks handles and threads when threads use sockets
I've been using clamav's clamd under cygwin and noticed that over time the
handle count as viewed with TaskManager seems to grow to arbitrary values.
I used clamd's option IdleTimeout set to 600 seconds which dramatically
reduced the growth rate of the Handle Count. Of course clamd has many
things going on that could contribute to handle leakags, so I tried to write
a simple program to demonstrate the problem.
The attached program demonstrates the problem when sockets are used and that
things look pretty clean when they are not.
There seems to be both a thread leakage issue and a separate handle leakage
issue.
Invoking the program as:
threadtest -sockets 0
creates groups of 5 threads simultaneously. Each thread merely prints
something and sleeps, prints something else and exits. This is repeated 10
times displaying the process handle count between each iteration. While
running and watching with Task Manager, the process thread counts seems to
start at 2 and reach 7 at times and then return to 2. The handle count
grows during the first iteration but stays flat thereafter.
Invoking the program as:
threadtest -sockets 3
creates groups of 5 threads simultaneously. Each thread merely prints
something and sleeps, connects a socket to the main thread, passes a little
data and closes the socket. This socket business is repeated 3 times after
which the thread prints something else and exits. This is repeated 10 times
displaying the process handle count between each iteration. While running
and watching with Task Manager, the process thread counts seems to start at
2 and reach 14 during the each iteration and drops back to 9 between
iterations. The handle count grows significantly during the first iteration
but seems to grow by 10 or 11 between each subsequent iteration.
The -sockets 3 argument controls the number of sockets each thread creates
during its life. The amount of thread and handle leakage seems to be
independent of the number of sockets the thread uses during its lifetime (as
long as the number of sockets used is 1 or greater).
The number of threads created simultaneously can be controlled by
specifying -threads n as command arguments. The number of threads leaked
seems to be directly related to the number of thread using sockets
concurrently. running the program with -sockets 3 and -threads 10 causes
the thread count to jump to 24 during each iteration and drop back to 14
between iterations, while the handle count seems to increase by 10 or 11
between each iteration identical to the case described in the previous
paragraph.
I hope this test can help someone familar enough with cygwin internals to
help get this problem under control.
- Mark Pizzolato
Attachment:
threadtest.c
Description: Text document
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/