sub queueProcessRequest { my ($job) = @_; $throttle->down(); $dispatcher->enqueue($job); return undef } #### sub syncIdle { # Check if any thread errored out my $abort = 0; for my $i (0..$#thread) { if ( !$thread[$i]->is_running() || $thread[$i]->is_joinable() ) { lock($screenaccess); print (STDERR 'ERROR: thread #' , 1+$i , ' encountered a problem while processing file' , "\n" , $log[1+$i] , "\n" , 'Check the cause and eventually report a bug.' , "\n" ); $abort ||= 1; } } if ($abort) { endThreadedOperation(); print (STDERR "${VTred}Flushing and aborting now ...${VTnorm}\n"); print (STDERR 'The error message may have scrolled out due to asynchronous operation. Check.', "\n"); exit(1); } while ($busy || 0 < $dispatcher->pending()) { threads->yield(); # sleep(1); # Retry later } } #### sub queueProcessRequest { my ($job) = @_; # If the queue fills up, it may be caused by threads killed # by an error. In this case, we'll be blocked forever below. # Then let's have a look on the threads. if ($queuelen <= $dispatcher->pending()) { # threads->yield(); sleep(1); # Give a chance foreach my $t (@thread) { if ( !$t->is_running() || $t->is_joinable() ) { syncIdle(); # Diagnose and abort } } } $throttle->down(); $dispatcher->enqueue($job); return undef }