Hm. I only just now notice your silent update. That also .... rude.

Ignoring lots of strange stuff in your code, like:

sub initThreads{ my @initThreads; for(my $i = 1;$i<=$num_of_threads;$i++){ push(@initThreads,$i); } return @initThreads; } # use the initThreads subroutine to create an array of threads. my @threads = initThreads();

Which does exactly the same as:my @threads = 1 .. $num_of_threads; but in an obscure and very costly way; and has absolutely nothing to do with threads -- it doesn't create threads; nor init threads; nor anything else to do with threads...

C'est la vie. Pressing on.

The problem: when you do this:

$hash1{$affix}{$postfix} = threads::shared::shared_clone([$affix1]); +This is where the problem is. How can I assign an array to a hash of +hash

You get: Thread 1 terminated abnormally: Invalid value for shared scalar..

The problem is that whilst my %hash1 :shared; is shared, the nested hash required by

$hash1{ $affix } { $postfix } = ...; #................^^^^^^^^^^^^

Is being autovivified; and is therefore not shared. So, to assign that you need to do:

$hash1{ $affix } = &share( {} ); ## Add an empty shared hash ## THEN you can do $hash1{ $affix }{ $postfix } = ....

But, the end of that line is also weird:

..................... threads::shared::shared_clone( [ $affix1 ] );

You are taking a simple scalar, making an unshared, single entry array from it, then cloning that into a shared, single entry array.

Are you sure you need an array here?


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked

In reply to Re: Multithreading How do I share hash of hash of arrays by BrowserUk
in thread Multithreading How do I share hash of hash of arrays by kdarbs

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.