threads::shared seems only serve for simple array, scalar or hash.
Look again at threads::shared::shared_close(). Eg:
use threads;; use threads::shared; my @r = ( map+{ map{ $_ => [ 1 .. 10 ] } 'a' .. 'z' }, 1..10 );; pp \@r;; [ { a => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], b => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], c => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], d => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], e => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], f => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], g => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], h => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], i => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], j => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], k => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], l => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], "m" => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], n => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], o => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], p => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], "q" => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], r => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], "s" => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], t => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], u => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], v => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], w => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], "x" => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], "y" => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], z => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], }, { a => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], ... }, ] my @s : shared = map shared_clone( $_ ), @r; pp \@s; [ # tied threads::shared::tie { # tied threads::shared::tie a => [ # tied threads::shared::tie 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ], b => [ # tied threads::shared::tie 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ], c => [ # tied threads::shared::tie 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ], d => [ # tied threads::shared::tie ... ], ... }, { # tied threads::shared::tie a => [ # tied threads::shared::tie 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ], b => ... } ... ]
It won't clone subroutines, because that's not possible or logical.
However, whilst this allows you to share complex data structures, you'll generally find that it doesn't achieve what you think you want to achieve, and you'll probably come back asking why not.
If you would describe your application, there is usually a better way of achieving it.
In reply to Re: How to share complex data structure in threads ?
by BrowserUk
in thread How to share complex data structure in threads ?
by exilepanda
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |