in reply to Re^4: a question on sharing data structures across threads
in thread a question on sharing data structures across threads
Here's what might be considered a work-around for the limitation:
#! perl -slw use strict; use threads; use threads::shared; my $some_id = 1; ## Make the scalar shared my $scalar_data :shared = 'fred'; my %planets :shared; my %el :shared = ( 'data' => \$scalar_data, ## reference to shared scalar 'atime' => time, 'deleted' => 0, 'modified' => 0 ); $planets{$some_id} = \%el; ## Lock the shared hash (%el) by indirection lock %{ $planets{$some_id} }; ## Or lock the data itself via indirection lock ${ $planets{ $some_id }{ data } };
Seems a tad hookey, but it does allow you to lock the relevant sub-hash or piece of data without requiring you to lock the entire top-level hash.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: a question on sharing data structures across threads
by TOD (Friar) on Oct 09, 2007 at 10:04 UTC |