in reply to Threads and Shared Variables
It will work if you move the definition of $progref and the ch subroutine outside of your async block:
$ cat 1042506.pl #!/usr/bin/env perl use strict; use threads; use Thread::Queue; my $q=Thread::Queue->new; my $progref; my $thr=async { $progref=$q->dequeue; #This seems to create a local $progref, but +it shouldn't! print "In main part of thread \$progref=$progref\n"; $$progref=30; #This is applied ch(); #This is ignored }; my $prog :shared; $q->enqueue(\$prog); sleep 2; print "$prog\n"; #Prints 30, not 90 $q->end; $thr->join; sub ch { print "In ch \$progref=$progref\n"; #progref is still undefined (w +hy?) $$progref=90; } $ perl 1042506.pl In main part of thread $progref=SCALAR(0x84bfa60) In ch $progref=SCALAR(0x84bfa60) 90
...roboticus
When your only tool is a hammer, all problems look like your thumb.
|
|---|