in reply to Threads and print
...<hem>that's 6 threads, shirly ?my @threads = map { ## create the workers passing the log file handle and semaphore threads->create( \&worker, $log, \$logSem,$_*$N, $_*$N + $N -1); } 0 .. 5; ## 5 threads each processing 100 "files"
To process $from..$to in $t threads, how about:
and in the thread:my @threads = map{ threads->create( \&worker, $log, \$logSem, $from + ($_ - 1), $t, $to +) ; } 1 .. $t ;
which deals with the number of files not being an exact multiple of the number of threads, and copes with $from..$to range where $from is not zero and $to is included in the range...my( $log, $semRef, $from, $step, $to ) = @_; for (my $file = $from ; $file <= $to ; $file += $step) { ...... } ;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Threads and print
by sandy1028 (Sexton) on Apr 16, 2009 at 09:52 UTC | |
by cdarke (Prior) on Apr 16, 2009 at 11:40 UTC | |
by sandy1028 (Sexton) on Apr 17, 2009 at 04:57 UTC | |
by sandy1028 (Sexton) on Apr 20, 2009 at 06:06 UTC |