develooper Front page | perl.ithreads | Postings from December 2007

Re: Lexical Object copied to new thread

Thread Previous | Thread Next
From:
Elizabeth Mattijsen
Date:
December 23, 2007 11:02
Subject:
Re: Lexical Object copied to new thread
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

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About