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
> [email protected]
> http://perl.org.il/mailman/listinfo/perl
_______________________________________________
Perl mailing list
[email protected]
http://perl.org.il/mailman/listinfo/perl