[Israel.pm] Lexical veriable copyed with new thread

Shmuel Fomberg semuelf at 012.net.il
Sat Dec 22 15:50:30 PST 2007


Thanks Peter.

I tested it in the Komodo debugger and Perl -d, but could not get any error.


So I changed the object creation line to:
    my $x = bless {Name=>"Moshe"}, 'Obj';
And the DESTROY to:
sub Obj::DESTROY {
    my $self = shift;
    print "Object ", $self, " whose name is ", $self->{Name};
    print " Destroyed from thread ", threads->tid, "\n";
}
and got the following output:
Thread running.. Done.
Object Obj=HASH(0x18c4578) whose name is Moshe Destroyed from thread 1
Object Obj=HASH(0x226c00) whose name is Moshe Destroyed from thread 0

This says to me that the object was copied, along with its data.

I don't know what is bug and what is suppose to be anymore.

Shmuel.

(testing on ActiveState Perl 5.8.8 build 822)

>-----Original Message-----
>From: perl-bounces at perl.org.il [mailto:perl-bounces at perl.org.il] On Behalf
>Of Peter Gordon
>Sent: Saturday, December 22, 2007 10:57 PM
>To: Perl in Israel
>Subject: Re: [Israel.pm] Lexical veriable copyed with new thread
>
>It is clear the $x was copied to the new thread, and destroyed when it
>ended
>
>It isn't clear that $x was copied to the new thread. But it is clear
>that the DESTROY was called spuriously from the thread. It looks like a
>bug.
>
>If you run the program with the debugger, you get
>Use of uninitialized value in subroutine entry at a1.pl line 15 during
>global destruction.
> at a1.pl line 15
>	Obj::DESTROY('Obj=HASH(0x9d3af14)') called at a1.pl line 0
>	eval {...} called at a1.pl line 0
>
>which seems to imply that the value was not copied.
>
>Peter
>
>
>
>On Sat, 2007-12-22 at 20:03 +0200, Shmuel Fomberg wrote:
>> Hi All.
>>
>> Please observe to following program:
>> --- Start Code
>> #!/usr/bin/perl -w
>> use strict;
>> use threads;
>>
>> sub thr {
>>     print "Thread running.. Done.\n";
>> }
>>
>> sub run_test {
>>     my $x = bless {}, 'Obj';
>>     threads->create(\&thr)->join();
>> }
>>
>> sub Obj::DESTROY {
>>     print "Destroyed from thread ", threads->tid, "\n";
>> }
>>
>> run_test();
>> --- End Code
>>
>> The output that I get is:
>> Thread running.. Done.
>> Destroyed from thread 1
>> Destroyed from thread 0
>>
>> It is clear the $x was copied to the new thread, and destroyed when it
>> ended.
>> But why? $x is not a global, and not passed as parameter to the thread's
>> entry point. Why Perl copy it?
>>
>> Sometimes I think that I don't understand anything at all... T_T
>>
>> Shmuel.
>>
>>
>> _______________________________________________
>> Perl mailing list
>> Perl at perl.org.il
>> http://perl.org.il/mailman/listinfo/perl
>
>_______________________________________________
>Perl mailing list
>Perl at perl.org.il
>http://perl.org.il/mailman/listinfo/perl
>
>
>--
>No virus found in this incoming message.
>Checked by AVG Free Edition.
>Version: 7.5.516 / Virus Database: 269.17.6/1192 - Release Date: 21/12/2007
>13:17




More information about the Perl mailing list