Perl Monk, Perl Meditation | |
PerlMonks |
threads and low values with Time::HiRes::setitimerby revdiablo (Prior) |
on Sep 05, 2003 at 23:40 UTC ( [id://289385]=perlquestion: print w/replies, xml ) | Need Help?? |
revdiablo has asked for the wisdom of the Perl Monks concerning the following question: Lately I have been playing with threads and Time::HiRes::setitimer. I find it's a pretty neat way to have many threads do something roughly simultaneously. It works quite well, and I haven't had any major problems -- until I started using low values for the interval. I'm trying to have a bunch of worker threads update their state every 0.1 seconds. So I wrote a little script to play around with threads and timers:
With $NUM set to 5, things seem to work as expected. Here's some sample output:
First, notice that my system is creating about 63 threads per second (this number is actually fairly stable, surprisingly). That's about 6 threads in 1/10th of a second. Now, notice how close the time values are for thread 5 in the 1st group and main in the 2nd group. Where I'm getting problems is when I try to use more threads than my system can construct in 1/10th of second. If I change $NUM to 7, I get unreliable and unexpected behavior. Sometimes the groups just overlap, as I would expect. Sometimes perl segfaults. Sometimes I get "runaway" threads that don't seem to follow the interval timer at all. I'm not sure what's causing this behavior, and frankly it's out of my league trying to figure it out. What my question is really about, is what can I do to workaround this? I can think of a few possible solutions:
Hopefully the ever reliable monks will come up with some ideas for me... :)
Back to
Seekers of Perl Wisdom
|
|