RE: @{$self->{container}} share question

[email protected] ("Jack Steadman")
Newsgroups perl.ithreads
Message-ID <[email protected]>
some suggestions are below.  unfortunately i'm not able to test them out
right now, but in my experience they should work.  i apologize if they don't
for some reason.

> package test;
>
> use strict;
> use threads;
> use threads:shared;
>
> sub new {
>    my $class = shift;
>    $class = ref($class);
>    my $self = {};

change to: my $self = &share({});

>    # doesn't like the following in a shared scenario
>    @{$self->{container}} = ();

try: $self->{container} = &share([]);

>    bless $self, $class;
>    return $self;
> }
>
> sub push : locked method {
>    my $self = shift;
>    my @stuff = ();
>    @stuff = @_;
>    if (scalar @stuff > 0) {
>       # whines about the @{$self->{container}} and sharing here.  Why?
>       push(@{$self->{container}},@stuff);

try changing declaration above to: my @stuff : shared = ();

>    }
> }
> 1;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.