2 # prime-pthread, courtesy of Tom Christiansen
10 my $stream = Thread
::Queue
->new();
11 for my $i ( 3 .. 1000 ) {
14 $stream->enqueue(undef);
16 threads
->create(\
&check_num
, $stream, 2);
20 my ($upstream, $cur_prime) = @_;
22 my $downstream = Thread
::Queue
->new();
23 while (my $num = $upstream->dequeue()) {
24 next unless ($num % $cur_prime);
26 $downstream->enqueue($num);
28 print("Found prime $num\n");
29 $kid = threads
->create(\
&check_num
, $downstream, $num);
33 $downstream->enqueue(undef);
This page took 0.38651 seconds and 4 git commands to generate.