in reply to use Devel::Pointer in threads
> I know threads::shared can't share deep data structure,
according to the docs that's not true, you can share deep data structures as long as you also share any nested reference.
share(VARIABLE)Shared variables can only store scalars, refs of shared variables, or refs of shared data (discussed in next section):
> and any fix for this approach?
You can always use shared_clone for read access.
And of course you can explicitly share singular scalars inside your nested data structure to allow writing.
shared_clone(REF)shared_clone takes a reference, and returns a shared version of its argument, performing a deep copy on any non-shared elements. Any shared elements in the argument are used as is (i.e., they are not cloned).
If that's not good enough because you can't/don't want to predict the structure of your nested data, you might try Data::Dumper or Data::Dump for serializing it into a shared string. The receiving end can easily unpack it again.
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: use Devel::Pointer in threads
by exilepanda (Friar) on Apr 05, 2021 at 01:21 UTC | |
by LanX (Saint) on Apr 05, 2021 at 11:45 UTC |