|
Hi forum,
Right now perl_clone clones all lexicals in any scope in the call frame chain of threads->create() as show in the following, tested with perl 5.8.8 and threads 1.62
#!/usr/bin/perl -w
use threads;
sub Foo::DESTROY { warn "In destroy: ".threads->tid."\n" }
sub thr {}
sub create {
threads->create('thr')->join();
}
sub f {
my $foo = bless {},'Foo';
threads->create('thr')->join();
create();
}
f();
That undocumented behaviour causes that the lexicals are leaked until thread destruction because there are totally hidden, contributes to overhead of thread creation, and worse, where they are XS objects, causes all sort of problems at destruction time ("free to wrong pool", crashes, etc), and not because the object isn't "thread safe" but by unsuspected cloning.
IMHO threads->create should only clone the visible variables (global or lexical) in the scope of the entry point function.
Until fixed, the bug must be documented.
Also I think that the documentation should include info about $class->CLONE and $class->CLONE_SKIP methods as aids for "thread safety".
Best regards.
Salvador.
|