Thread globale $vars in Thread bearbeiten
(2 answers)
Opened by pearl-man at 2006-05-22 14:13
Ich glaube, du musst die Variable zwischen den Threads sharen:
Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 use threads; use threads::shared; my $foo : shared = 1; my $bar = 1; threads->new(sub { $foo++; $bar++ })->join; print "$foo\n"; #prints 2 since $foo is shared print "$bar\n"; #prints 1 since $bar is not shared Siehe auch "Shared And Unshared Data" in Perl Thread Tutorial |