Try it this way:
#! perl -slw use strict; use threads; use threads::shared; my %h :shared; $h{ 1 } = &share( {} ); $h{1}{2} = 3; { lock %{ $h{1} }; ## <<<< async { print "2:Waiting for lock"; lock %{ $h{1} }; print "2:lock acquired"; $h{1}{2} = 10; print '2:lock released'; }->detach; sleep 2; } print "1:Waiting for lock"; lock %{ $h{1} }; print $h{1}{2}; __END__ c:\test>junk70 2:Waiting for lock 1:Waiting for lock 2:lock acquired 2:lock released 10
It shouldn't be necessary, but it does work.
In reply to Re: thread::shared - shared but not shared?
by BrowserUk
in thread thread::shared - shared but not shared?
by learnedbyerror
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |