sanc has asked for the wisdom of the Perl Monks concerning the following question:
This is the main sectionsub pullDataFromDbWithDirectory { my $_dir = $_[0]; if ($itemCount <= $maxNumberOfItems) { my @retval = grep { /^Dir|^File/ } qx($omnidb -filesystem $fil +esystem '$label' -listdir '$_dir'); foreach my $item (@retval) { $itemCount++; (my $filename = $item) =~ s/^File\s+|^Dir\s+|\n//g; my $file = "$_dir/$filename"; push(@data,$file); if ($item =~ /^Dir/) { $worker->enqueue($file); print "Add $file to queue\n" if $debug; } } } } sub doOperation () { my $ithread = threads->tid(); do { my $folder = $worker->dequeue(); print "Read $folder from queue with thread $ithread\n" if $debu +g; pullDataFromDbWithDirectory($folder); } while ($worker->pending()); push(@IDLE_THREADS,$ithread); }
my @threads = map threads->create(\&doOperation), 1 .. $maxNumberOfPar +allelJobs; pullDataFromDbWithDirectory($directory); sleep 0.01 while (scalar @IDLE_THREADS < $maxNumberOfParallelJobs); $worker->enqueue((undef) x $maxNumberOfParallelJobs); $_->join for @threads; printData();
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Proper undefine queue with multithreads
by BrowserUk (Patriarch) on Jun 03, 2014 at 13:15 UTC | |
by sanc (Initiate) on Jun 03, 2014 at 17:00 UTC | |
by BrowserUk (Patriarch) on Jun 03, 2014 at 20:08 UTC | |
by sanc (Initiate) on Jun 04, 2014 at 05:56 UTC | |
by BrowserUk (Patriarch) on Jun 05, 2014 at 12:55 UTC | |
| |
| |
|