in reply to Re^3: Protecting External Data?!
in thread Protecting External Data?!

My first reaction was that you don't know what you are talking about. of course the PAD of the function will exists, and be copied to the new thread. the content of the PAD should not be copied.

And then I tested it out:

#!/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();
and the output:
Thread running.. Done. Destroyed from thread 1 Destroyed from thread 0
So now I think that I don't know what I'm talking about.
Why did Perl copied the $x? it is not a global, and was not passed as parameter. I just don't get it.

If someone can point me to a relevant perldoc, I'll be greatefull.

thank,
Shmuel.

Replies are listed 'Best First'.
Re^5: Protecting External Data?!
by plobsing (Friar) on Dec 23, 2007 at 05:10 UTC
    from perlthrtut:

    The biggest difference between Perl ithreads and the old 5.005 style threading, or for that matter, to most other threading systems out there, is that by default, no data is shared. When a new Perl thread is created, all the data associated with the current thread is copied to the new thread, and is subsequently private to that new thread! This is similar in feel to what happens when a UNIX process forks, except that in this case, the data is just copied to a different part of memory within the same process rather than a real fork taking place.