Re: Threads and OO Question

From: Edward Wildgoose (Ed+nospam_at_ewildgoose.demon.co.uk@)
Date: 10/16/03


Date: Thu, 16 Oct 2003 09:05:52 GMT


> > I say this because the docs on threads::shared (have you looked at
> > threads::shared?) says that
> >
> > " 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. This is expected to be implemented
> > in a future version of Perl."

Aha, some further research on this shows that the warning is just a warning.
Basically it means that you should bless after sharing, not before. It
doesn't seem to be a limitation on blessing objects, ie the sample code now
becomes:

package MyStats;
use threads::shared;

sub new {
    my $class = shift;
    my $this = { bytes_in => 0,
                 bytes_out => 0};
    bless($this, $class);
    share($this);
    return $this;
}

Further interesting observations (on Activestate perl at least) are that now
"MyStats" is shared, if I then create a worker thread variable of type
MyStats in the scope of the worker thread package, this itself is
automatically shared even if I don't share it in the worker thread, ie I can
see it from the main thread.

I can't decide if this is expected or not to be honest? I need to test
locking now I suppose... Will it work properly with objects...?

There must be some good samples on this kind of stuff somewhere though?

Thanks all

Ed W



Relevant Pages

  • Hmmm. What is the Biblical meaning of bless, blessed, blessing? (Was Re: Is Jesus Spirit in You?)
    ... >>>God Bless, ... >> asking Him to bless? ... thing, pray him to bless it to one's use, pronounce a consecratory blessing ... How about the Hebrew and the Old Testament? ...
    (soc.religion.mormon)
  • Re: Blessing query
    ... It tells the machine which copy of the OS to run when booting. ... assistance which blessing can give. ... IIRC on OS 9 if you dragged the Finder in and out of a "System Folder", ... preferences pane calls bless under the hood. ...
    (uk.comp.sys.mac)
  • Re: Baby Blessings
    ... Because babies need blessings? ... official church-building style blessing won't happen for another 8 ... I would get a chance for any course corrections ... I didn't bless any of them to be an example to their ...
    (soc.religion.mormon)
  • Re: Baby Blessings
    ... I didn't bless any of them to be an example to their ... > siblings, didn't bless any of them to grow up and serve a mission, ... > didn't bless any of them that they would marry in the temple. ... When I went to bless my little boy, I specifically went into the blessing ...
    (soc.religion.mormon)