Daniel, If, by thread count, you are referring to the thread id of each newly spawned thread, that will always increment. If you are referring to the total number of running threads at any given time, you should either $tid->detach or (better yet) $tid->join for each thread you have spawned at the end of the main thread's loop. This will insure that you wait for all spawned threads to complete and release their resources (as best as possible).
However, based on what you have stated your application requirements to be, it sounds like you might be better off redesigning your application to pre-create N worker threads, where N=6 (the max number of resources you can process at any given time in your case). Then, try using Thread::Queue or Thread::Queue::Any to create a queue that the main thread populates and the worker threads block on, waiting for data to process. Alternatively, with regards to thread-induced memory growth that you have been trying to resolve in your current script, I recommend you try forks.pm (search for "forks" on CPAN). It is a drop-in replacement for threads.pm that implements the complete ithreads interface (written with an alternate underlying structure that does not suffer any of common memory growth issues that affect long-running threads.pm-based applications, especially those that spawn and release many threads). -Eric Rybski --- Daniel Rychlik <[EMAIL PROTECTED]> wrote: > Good morning, > > > > I am having troubles with threads within my PERL service which was built > to monitor a queue for jobs to do. The issue I am running into is, I > have an unknown number of jobs to do but can only do 6 at one time. The > reason that I can only do 6 at one time is because I only have 6 > resources available to me for each job. > > > > I looked into using threads to do the jobs asynchronously, as a file > comes into a queue; a loop monitors this queue and then creates a new > thread to carry out that job. I have this piece of the code complete, > the problem is after the job is complete and a list of instructions is > complete, the thread doesn't clean up after itself. My thread count > continues to increment as well as memory space. The loop that I use to > monitor the queue is a while true loop and it sleeps for 2 minutes > waiting for more files to process and upload. > > > > I need help on how to clean up after a thread to release its resource. > I have researched this for 2 days now and Im growing weary. It was > suggested to me to subscribe to this list to find out more information. > > > > > I greatly appreciate this in advance, > > Dan J. Rychlik > >
