Hi Dave.

I thought that the new thread keeps the chain of calls, and when it being
destroyed it will release the objects by the reverse order of the calling
stack. Apparently not.

So in the new thread, who holds the references for all those waiting
scalars? Or does keeps all the other stacks (beside the calling one) and
they hold the references?

Anyway, it makes some sense. So package function like CLONE need not wonder
if the object was copied or not. All the objects are copied.

I made this example:
---- Begin Code
our $x;
sub run_test {
    local $x = bless {Name=>"Haim1"}, 'Obj';
    my $y = bless {Name=>"Haim2"}, 'Obj';
    {
        local $x = bless {Name=>"Moshe1"}, 'Obj';
        my $y = bless {Name=>"Moshe2"}, 'Obj';
        threads->create(\&thr)->join();
    }
}
---- End code

and got output:
Object Obj=HASH(0x18cc01c) whose name is Haim2 Destroyed from thread 1
Object Obj=HASH(0x18cc040) whose name is Moshe2 Destroyed from thread 1
Object Obj=HASH(0x18c4cc8) whose name is Moshe1 Destroyed from thread 1
Object Obj=HASH(0x18302f0) whose name is Moshe2 Destroyed from thread 0
Object Obj=HASH(0x226d74) whose name is Moshe1 Destroyed from thread 0
Object Obj=HASH(0x226cfc) whose name is Haim2 Destroyed from thread 0
Object Obj=HASH(0x226c00) whose name is Haim1 Destroyed from thread 0

I see that Haim1, being a masked global, was not copied. This kinda breaks
my earlier "make sense". Oops.
Also Moshe1, as global, was destroyed last. 
Is this order of destroy is completely random? Or does it make any sense?

Help?
Shmuel.

>-----Original Message-----
>From: Dave Mitchell [mailto:[EMAIL PROTECTED]
>Sent: Monday, December 24, 2007 12:12 AM
>To: Shmuel Fomberg
>Cc: perl-ithreads@perl.org
>Subject: Re: Lexical Object copied to new thread
>
>On Sun, Dec 23, 2007 at 11:59:21PM +0200, Shmuel Fomberg wrote:
>> Hi Dave.
>>
>> >> Anyway, my question is that $x is a lexical inside run_test, and as
>much
>> >>as
>> >> I understood it was not suppose to be copied to the new thread. But it
>> >is.
>>
>> >In a new thread, *everything* is copied, apart from the calling stacks.
>>
>> Well, It seen that the calling stack is copied too. But it kept frozen
>until
>> the thread is destroyed, and then Perl destroy the calling stack frame by
>> frame.
>
>Um no, lexical variables aren't stored on the call stack. The stack isn't
>copied (so caller() in a thread won't show any history outside the thread
>itself), but all lexicals are cloned.
>
>--
>But Pity stayed his hand. "It's a pity I've run out of bullets",
>he thought. -- "Bored of the Rings"
>
>
>--
>No virus found in this incoming message.
>Checked by AVG Free Edition.
>Version: 7.5.516 / Virus Database: 269.17.8/1195 - Release Date: 24/12/2007
>11:19


Reply via email to