[ale] Invalid value for share scalar?

Christopher Fowler cfowler at outpostsentinel.com
Mon Oct 2 21:00:26 EDT 2006


The problem is that I'm trying to share a reference.

>From 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. For example:

    use threads;
    use threads::shared;
    my $var           = 1;
    my $svar : shared = 2;
    my %hash : shared;
    ... create some threads ...
    $hash{a} = 1;       # all threads see exists($hash{a}) and $hash{a} == 1
    $hash{a} = $var     # okay - copy-by-value: same effect as previous
    $hash{a} = $svar    # okay - copy-by-value: same effect as previous
    $hash{a} = \$svar   # okay - a reference to a shared variable
    $hash{a} = \$var    # This will die
    delete $hash{a}     # okay - all threads will see !exists($hash{a})


I would have really liked to have created a Packet object and placed that 
onto the stack (array) of packets to be processed.


On Mon, 2006-10-02 at 14:07 -0400, Jim wrote:
> Christopher Fowler wrote:
> > On Mon, 2006-10-02 at 13:12 -0400, Watson, Keith R. wrote:
> >   
> >> Chris,
> >>
> >> I'm unfamiliar with the syntax of line 39. What is it supposed to do?
> >>     
> >
> > It makes the array shared across threads.  I'm using threads and the
> > error message I'm getting is specific to threads.
> >
> > If a value is not shared then it will get a copy of the data just like
> > with a fork().
> >
> >   
> >> keith
> >>     
> >
> > _______________________________________________
> > Ale mailing list
> > Ale at ale.org
> > http://www.ale.org/mailman/listinfo/ale
> >
> >
> >
> >   
> Anything that goes into that shared object also has to be declared shared. 
> 
> push(@objs,"hi");   is OK
> push(@objs,$xyz); isn't unless $xyz is declared shared also.    I'm not 
> sure why it flags it there however unless catch is being called with @obj.
> 
> Jim.
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://www.ale.org/mailman/listinfo/ale




More information about the Ale mailing list