Thread globale $vars in Thread bearbeiten (2 answers)
Opened by pearl-man at 2006-05-22 14:13

nepos
 2006-05-22 14:21
#66409 #66409
User since
2005-08-17
1420 Artikel
BenutzerIn
[Homepage] [default_avatar]
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

View full thread globale $vars in Thread bearbeiten