pg has asked for the wisdom of the Perl Monks concerning the following question:

I believe this is a serious bug in Perl 5.8 with thread + OO (I am hoping this is actually a mistake on my side, so I bring this to monks)

Try the following code, and uncomment either of the two commented lines. Compare the result from both cases, and you will see that, if %hash itself is shared, you would not be able to assign $hash{VALUE} to an Object of Something correctly. Perl loses the object type, and simple coverts it into an unblessed hashref. Hence, you would not be able to call any method defined on that Object.

use Something; use threads; use threads::shared; use strict; use warnings; #my %hash : shared; #my %hash; $hash{VALUE} = &share(new Something(1)); print $hash{VALUE}; package Something; sub new { shift; my $self = {}; $self->{VALUE} = shift; bless($self); return $self; } 1; 1;

Replies are listed 'Best First'.
Re: thread + oo, and a possible serious bug.
by robartes (Priest) on Feb 06, 2003 at 08:02 UTC
    Hi pg,

    it's a feature, not a bug. From thread::shared docs:

    "bless" is not supported on shared references. In the cur- rent version, "bless" will only bless the thread local reference and the blessing will not propagate to the other threads. This is expected to be implemented in a future version of Perl.
    Then again, this is listed in the BUGS section, so there you go :)

    CU
    Robartes-