pome23 has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use threads; use Thread::Queue; use myClass; use warnings; use Fcntl ':flock'; my $q = Thread::Queue->new(); open(FILE,"database.txt"); open(FILE2,">>answers.txt"); $q->enqueue($_) while(<FILE>); for(0 .. 9) { threads->new(\&worker, $q); } $_->join for threads->list; sub worker { my $queue = shift; while( my $item = $queue->dequeue) { chomp($item); my $p = myClass->new(); my $physics = $p->getRandom(); flock(FILE2,LOCK_EX); print FILE2 "$item|$physics"; print "$item|$physics"; flock(FILE2,LOCK_UN); } return; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Slow worker threads
by BrowserUk (Patriarch) on Jul 18, 2009 at 00:36 UTC | |
|
Re: Slow worker threads
by jrsimmon (Hermit) on Jul 17, 2009 at 23:54 UTC | |
|
Re: Slow worker threads
by ig (Vicar) on Jul 18, 2009 at 06:09 UTC | |
by spx2 (Deacon) on Jul 18, 2009 at 17:56 UTC | |
by spx2 (Deacon) on Jul 18, 2009 at 19:20 UTC | |
|
Re: Slow worker threads
by pome23 (Initiate) on Jul 18, 2009 at 14:34 UTC |