#----------------------------------------------------------- use 5.008; use strict; use threads qw(yield); use threads::shared (); use Time::HiRes qw(sleep); our @GlobalArray : shared = (1..1000); my $sub1 = sub { while (1) { my $a; { lock @GlobalArray; $a = shift @GlobalArray; } print $a, "\n"; yield; sleep 0.05; } }; my $t1 = new threads $sub1; my $t2 = new threads $sub1; my $t3 = new threads $sub1; $t1->detach; $t2->detach; $t3->detach; while (1) { # readFile(); # ... push @GlobalArray, (1..1000) unless scalar @GlobalArray; sleep 0.001; } 1; #-----------------------------------------------------------