Hello,

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?

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; }
In Foo::run() I cannot get the splice to work. The output/error is as follows:
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


In reply to Threading: Removing an element from a shared array by P0w3rK!d

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.