in reply to Re: Annoying threads share problem!
in thread Annoying threads share problem!

you will see that blessed things cannot be shared
No, shared things can't be (usefully) blessed, which is quite different. This is valid code:
my $x = bless [], 'X'; share $x;
The main problem with shared objects is that their destructor currently gets called multiple times, once per thread.

Dave.

Replies are listed 'Best First'.
Re^3: Annoying threads share problem!
by BrowserUk (Patriarch) on Oct 09, 2005 at 12:35 UTC

    Perhaps you'd comment on the disparity between that and this?

    use threads; use threads::shared;; my $x:shared = bless [], 'X'; Invalid value for shared scalar at (eval 4) line 1, <STDIN> line 2.

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
      Invalid value for shared scalar at (eval 4)
      You can only assign shared values to a shared variable. This works:
      my $obj = bless [], 'X'; share $obj; my $x:shared = $obj;

      Dave.

Re^3: Annoying threads share problem!
by castaway (Parson) on Oct 09, 2005 at 13:46 UTC
    I haven't gotten it reliably working either way, can you give a working example?

    C.

      I haven't gotten it reliably working either way, can you give a working example?
      Well, it depends rather on what exactly you are referring to as it, but
      use threads; use threads::shared; sub X::DESTROY { warn "X::DESTROY(@_)\n" } my $x = bless [], 'X'; share $x; $x->[0] = 1; sub f { $x->[0]++; warn "x->[0] = $x->[0]\n"; } threads->new(\&f)->join for 1..5; __END__ $ perl587t /tmp/p x->[0] = 2 X::DESTROY(X=ARRAY(0x9d8b218)) x->[0] = 3 X::DESTROY(X=ARRAY(0x9da0500)) x->[0] = 4 X::DESTROY(X=ARRAY(0x9da0500)) x->[0] = 5 X::DESTROY(X=ARRAY(0x9da0500)) x->[0] = 6 X::DESTROY(X=ARRAY(0x9da0500)) X::DESTROY(X=ARRAY(0x9cd3c30))

      Dave.