Re: Lexical Object copied to new thread
[email protected] (Elizabeth Mattijsen) Sun, 23 Dec 2007 20:02:24 +0100
| Newsgroups | perl.ithreads |
|---|---|
| Message-ID | <p06230904c394612b16e4@[10.0.1.198]> |
At 8:58 PM +0200 12/23/07, Shmuel Fomberg wrote:
>Hello List.
>
>Please observe the following code:
>---- start code
>#!/usr/bin/perl -w
>use strict;
>use threads;
>
>sub thr {
> print "Thread running.. Done.\n";
>}
>
>sub run_test {
> my $x = bless {Name=>"Moshe"}, 'Obj';
> threads->create(\&thr)->join();
>}
>
>sub Obj::DESTROY {
> my $self = shift;
> print "Object ", $self, " whose name is ", $self->{Name};
> print " Destroyed from thread ", threads->tid, "\n";
>}
>
>run_test();
>---- end code
>
>On ActiveState Perl 5.8.8 build 822, with threads 1.63, I get the following
>output:
>Thread running.. Done.
>Object Obj=HASH(0x18c42f0) whose name is Moshe Destroyed from thread 1
>Object Obj=HASH(0x226f70) whose name is Moshe Destroyed from thread 0
>
>What I conclude from this is that the object is being copied to the new
>thread, along with its data, and is destroyed when the thread ends.
>
>Is it bug or feature?
You might want to check my Thread::Bless module on CPAN in this respect.
Liz