I have a GUI app (written in Perl/Tk) that uses a few dozen threads and the Boss/Worker model to manage background tasks. The app runs very slowly unless the threads sleep periodically (using the select command), in which case the GUI runs very quickly. What is going on?
Here is an untested code snippet:
while (1) {
eval {
if (my $key = $Queue->dequeue_nb) {
do_something();
}
};
if ($@) {
LOG("problem");
}
select undef, undef, undef, 1.00;
}
If I comment out the select command, the GUI runs an order of magnitude more slowly. What is the cause of this behavior?