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:

i'm running Perl 5.6, are threads and threads::shared available/stable
in this version?


>
> #!/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;

^ what is this?

> # make runtime vary a little for
> # demonstration purpose
> select undef, undef, undef, rand;
> }
> }
>
>

.



Relevant Pages

  • Re: optimize log parsing
    ... > Extremely easy with threads. ... > spawns off a number of threads where each thread pulls data from a ... # Terminates the child process ...
    (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)