Re: Threads and OO Question
From: Edward Wildgoose (Ed+nospam_at_ewildgoose.demon.co.uk@)
Date: 10/16/03
- Next message: Bernard El-Hagin: "Re: Emacs syntax highlight of Perl comments"
- Previous message: Alythh: "Emacs syntax highlight of Perl comments"
- In reply to: Edward Wildgoose: "Re: Threads and OO Question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Bernard El-Hagin: "Re: Emacs syntax highlight of Perl comments"
- Previous message: Alythh: "Emacs syntax highlight of Perl comments"
- In reply to: Edward Wildgoose: "Re: Threads and OO Question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|