Re: optimize log parsing



>
> Extremely easy with threads. Here's a complete example of a program that
> spawns off a number of threads where each thread pulls data from a
> global queue until it is empty:
>
> #!/usr/bin/perl -w
>
> use strict;
>
> use threads;
> use threads::shared;
>
> use constant NUM_THREADS => 10;
>
> # shared queue visible to every thread
> my @queue : shared = 1 .. 30;
>
> # create threads
> my @threads;
> push @threads, threads->new("run") for 1 .. NUM_THREADS;
>
> # wait for all threads to finish
> $_->join for @threads;
>
> # code executed by each thread
> sub run {
> while (defined(my $element = pop @queue)) {
> printf "thread %i: working with %i\n", threads->tid, $element;
> # make runtime vary a little for
> # demonstration purpose
> select undef, undef, undef, rand;
> }
> }
>
>
>
> Don't think in terms of processes. If you're using processes for that
> kind of thing you'll need to find a way for them to communicate
> (possibly pipes, or maybe shared memory). Threads takes this work off
> your shoulders as they can share data in a simple and secure manner.
>

Tassilo, thank you very much for your help. If i could trouble you once
more for your insight...

What benefit does the thread model have that the following does not?
What drawbacks?

use Parallel::ForkManager;
$pm = new Parallel::ForkManager($MAX_PROCESSES);
foreach $data (@all_data) {
# Forks and returns the pid for the child:
my $pid = $pm->start and next;
... do some work with $data in the child process ...
$pm->finish; # Terminates the child process
}



> use bigint;
> $n=71423350343770280161397026330337371139054411854220053437565440;
> $m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($m+=8)<=200);

.



Relevant Pages

  • Re: optimize log parsing
    ... > Extremely easy with threads. ... > spawns off a number of threads where each thread pulls data from a ... Prev by Date: ...
    (comp.lang.perl.misc)
  • Re: optimize log parsing
    ... >> Extremely easy with threads. ... >> spawns off a number of threads where each thread pulls data from a ... These older threads were a pain especially since you had to write your ...
    (comp.lang.perl.misc)