shonorio has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I’m getting a strange error 'Invalid value for shared scalar' when I try do run one code like this:
use threads; use threads::shared; my %Inventory; my %Test; share ( %Inventory ); $Test{0}{0} = 1; $Test{0}{1} = 1; $Test{1}{0} = 1; $Test{1}{1} = 1; %Inventory = %Test;
If I remove the share function, it's running well, but I need to share the hash on threads and don't figure out way this happen.

Thanks

Solli Moreira Honorio
Sao Paulo - Brazil

Replies are listed 'Best First'.
Re: Error on assigning shared hash
by runrig (Abbot) on Apr 22, 2004 at 00:24 UTC
    You missed this part of perlthrtut:
    In the case of a shared array, all the array's elements are shared, and for a shared hash, all the keys and values are shared. This places restrictions on what may be assigned to shared array and hash elements: only simple values or references to shared variables are allowed - this is so that a private variable can't accidentally become shared. A bad assignment will cause the thread to die.
    Your hash values are neither simple nor shared.
      Runrig, thank you so much... I'm re-reading the perlthrtut to check this litle details.

      Solli Moreira Honorio
      Sao Paulo - Brazil