in reply to scalars, references and queues
Sharing a reference to something that isn't shared is an error. As threads::share says,
my $var :shared; $var = 1; # ok $var = []; # error $var = &share([]); # ok
Maybe Thread::Queue should handle references better. Fortunately, it's easy to fix. Just share the referenced hash.
my %hash :shared = ( ... ); $DataQueue->enqueue(\%hash);
or
# Fixed as per BrowserUK's reply. # Initialization must be done after share. my $href = share({}); %$href = ( ... ); $DataQueue->enqueue($href);
or
use Storable qw( freeze thaw ); my %hash = ( ... ); $DataQueue->enqueue(freeze(\%hash));
Untested.
Update: Added Storeable snippet. Rephrased some text.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: scalars, references and queues
by BrowserUk (Patriarch) on Aug 03, 2007 at 15:38 UTC |