1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#!/usr/bin/perl use threads; use strict; use warnings; sub test { my ($von, $bis) = @_; my @result = (); foreach my $i ($von .. $bis) { push @result, $i; } return @result; } my $from = 0; my $over = 10; my $until = 20; my $thread1 = threads->new( \&test, ($from, $over) ); my $thread2 = threads->new( \&test, ($over + 1, $until) ); my @res1 = $thread1->join(); my @res2 = $thread2->join(); print "@res1"; print "\n"; print "@res2"; print "\n";
1 2
my $thread1 = threads->new( { context => 'list' }, \&test, $from, $over ); my $thread2 = threads->new( { context => 'list' }, \&test, $over + 1, $until );