Threads and shared blessed references

Discussion in 'Perl Misc' started by Vetle Roeim, Jun 9, 2004.

  1. Vetle Roeim

    Vetle Roeim Guest

    Quote from threads::shared (Perl 5.8.3):

    "bless" is not supported on shared references. In the current version,
    "bless" will only bless the thread local reference and the blessing
    will not
    propagate to the other threads.

    In other words, it's not possible to share references to objects. I.e.
    the
    following shouldn't work:

    package Foo::Bar;
    use threads;
    use threads::shared;
    sub new { my $self = &share( {} ); bless $self, shift; }
    sub zot { print "zot\n"; }

    my $foo = Foo::Bar->new;

    threads->create( sub {
    $foo->zot;
    }
    )->join;

    Is that a correct interpretation? Because the code example does actually
    work
    without any problems.

    I also found a mail that indicates that blessing of sharede references
    should
    indeed work:

    <URL:http://groups.google.com/groups?selm=200306091100.h59B05PA018110%40smtp3.ActiveState.com&output=gplain>

    Umm... So I guess my question is: is it safe to share blessed references
    among
    threads? :)


    --
    Touch eyeballs to screen for cheap laser surgery!
    Vetle Roeim, Jun 9, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nick Marden
    Replies:
    0
    Views:
    1,056
    Nick Marden
    Jan 17, 2004
  2. Nick Marden
    Replies:
    1
    Views:
    124
    Ben Morrow
    Jan 20, 2004
  3. sbk

    pulling apart a blessed hash

    sbk, Jan 26, 2005, in forum: Perl Misc
    Replies:
    3
    Views:
    94
    Gary E. Ansok
    Jan 26, 2005
  4. Jon

    re-blessing a blessed reference

    Jon, Jul 25, 2005, in forum: Perl Misc
    Replies:
    2
    Views:
    194
  5. A. Farber
    Replies:
    9
    Views:
    111
Loading...

Share This Page