P0w3rK!d has asked for the wisdom of the Perl Monks concerning the following question:
I have a process with several threads of which each
needs to eliminate an element from a shared array
when it is done with it. It is referencing the
elements by index only. The thread number is the
same as the index. I have the threading working,
my class and its methods are working, but the array manipulation is not.
How do you remove an element from a shared array?
In Foo::run() I cannot get the splice to work. The output/error is as follows:our @aryItems : shared; # Update: line added after initial posting # Here is the Foo class package Foo; use threads; # pull in threading routines use threads::shared; # and variable sharing routines # create a new Foo object sub new { my $pkg = shift; my $self = { @_, ... }; return bless($self, $pkg); } sub run { my $self = Foo->new(@_); my $id = $self->{id}; ... print "Hello from thread $id.\n"; print "Item $aryItems[$id]\n"; splice(@aryItems, $id); return 1; }
Hello from thread 0. Item 1153.xml thread failed to start: Splice not implemented for shared arrays at C: +/Perl/lib/ threads/shared.pm line 37. Hello from thread 1. Item 400.xml thread failed to start: Splice not implemented for shared arrays at C: +/Perl/lib/ threads/shared.pm line 37. Hello from thread 2. Item 1175.xml thread failed to start: Splice not implemented for shared arrays at C: +/Perl/lib/ threads/shared.pm line 37. Hello from thread 3. Item 1238.xml thread failed to start: Splice not implemented for shared arrays at C: +/Perl/lib/ threads/shared.pm line 37.
Thanks :)
-P0w3rK!d
Added line per author - dvergin 2003-05-15
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Threading: Removing an element from a shared array
by BrowserUk (Patriarch) on May 15, 2003 at 21:01 UTC | |
by P0w3rK!d (Pilgrim) on May 15, 2003 at 21:07 UTC | |
by BrowserUk (Patriarch) on May 15, 2003 at 23:19 UTC | |
by P0w3rK!d (Pilgrim) on May 16, 2003 at 14:37 UTC | |
by P0w3rK!d (Pilgrim) on May 16, 2003 at 14:51 UTC | |
Re: Threading: Removing an element from a shared array
by rinceWind (Monsignor) on May 16, 2003 at 10:10 UTC | |
by P0w3rK!d (Pilgrim) on May 16, 2003 at 14:44 UTC |