use threads();
{
my $foo = 'bar';
sub foo () :lvalue { $foo }
}
threads->new(
sub {
foo = 'quux';
print 'thread: coderef = ', \&foo, $/;
print 'foo is ', foo, $/;
}
)->join;
print 'main: coderef = ', \&foo, $/;
print 'foo is ', foo, $/;
__END__
$ perl thrcl.pl
thread: coderef = CODE(0x8129538)
foo is quux
main: coderef = CODE(0x8060674)
foo is bar
####
use threads();
use threads::shared;
{
my $foo :shared = 'bar';
sub foo () :lvalue { $foo }
}
threads->new(
sub {
foo = 'quux';
print 'thread: coderef = ', \&foo, $/;
print 'foo is ', foo, $/;
}
)->join;
print 'main: coderef = ', \&foo, $/;
print 'foo is ', foo, $/;
__END__
$ perl thrcl.pl
thread: coderef = CODE(0x8163924)
foo is quux
main: coderef = CODE(0x80fe448)
foo is quux
##
##
$ perl thrcl.pl
Invalid CODE attribute: shared at thrcl.pl line 5
BEGIN failed--compilation aborted at thrcl.pl line 5.