Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Basically, i'm trying to literate over an array of over 4million entrys. At around 800 entrys the script just stops. I was thinking it was because of how large the array is. Should i just split the array into chunks, then go through each? how could i get this to work properly.#! perl -slw use strict; use threads qw[ yield ]; use threads::shared; use Thread::Queue; use Time::HiRes qw[ sleep ]; use constant NTHREADS => 30; my $pos :shared = 0; open FILE, '<', $ARGV[ 0 ] or die $!; my $size = -s FILE; sub thread { my $Q = shift; my $tid = threads->tid; while( my $line = $Q->dequeue ) { printf "%3d: (%10d, %10d) :%s", $tid, $pos, $size, $line; sleep rand 5; } } my $Q = Thread::Queue->new; my @threads = map threads->create( \&thread, $Q ), 1 .. NTHREADS; while( !eof FILE ) { sleep 0.001 while $Q->pending; for( 1 .. NTHREADS ) { $Q->enqueue( scalar <FILE> ); lock $pos; $pos = tell FILE; } } $Q->enqueue( (undef) x NTHREADS ); $_->join for @threads;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Splitting large array for threads.
by BrowserUk (Patriarch) on Jun 15, 2014 at 07:24 UTC | |
|
Re: Splitting large array for threads.
by biohisham (Priest) on Jun 15, 2014 at 04:22 UTC | |
by marioroy (Prior) on Dec 13, 2014 at 03:35 UTC | |
|
Re: Splitting large array for threads.
by perlfan (Parson) on Jun 16, 2014 at 20:49 UTC | |
|
Re: Splitting large array for threads.
by Anonymous Monk on Jun 16, 2014 at 21:39 UTC | |
by Anonymous Monk on Jun 17, 2014 at 03:17 UTC | |
|
Re: Splitting large array for threads.
by Preceptor (Deacon) on Jun 18, 2014 at 16:59 UTC | |
|
Re: Splitting large array for threads.
by marioroy (Prior) on Dec 13, 2014 at 05:01 UTC |