in reply to Multithreading How do I share hash of hash of arrays
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?
|
|---|