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

Reply via email to