in reply to CPU Leaking Threads

Change the yield in your MainReaper thread to:

sleep 1 until ($DoneFlag || $Timeout);

Yield just relinguishes the rest of the threads timeslice. It immediately becomes eligible for rescheduling. That means that if no other thread is available to run, you've coded a very tight loop that will happily consume as much cpu as is available. By using a sleep, you will avoid thrashing the cpu. If you need finer than 1 second resolution, use Time::HiRes::sleep or the 4-arg select.

Note: This is based upon my observations of what happens on Win32. Your OS may work differently.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^2: CPU Leaking Threads
by Trizor (Pilgrim) on Feb 21, 2007 at 22:43 UTC
    And in reply to myself, the same change should be made in the Timer routine.
      the same change should be made in the Timer routine.

      Yes indeed. I didn't notice the second yield() tucked away there in that compound statement.

      Out of interest. Did those changes fix the problem? Are you happy with the performance and function of the resulting code?


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        Yes it worked quite nicely. Less than 1% usage on idle. However some other comments have me re-evaluating the entire archetecture but thats a different matter.