On Wed May 18 09:46:43 2016, JDHEDDEN wrote:
Show quoted text> On 2016-05-18 12:02:06, EXODIST wrote:
> > This test detaches a thread and lets the parent thread end before the
> > detached thread.
>
> I don't think that is the case. The detached thread locks the queue
> that is being tested (line 34). This lock is not released until the
> thread exits its subroutine at which point is will start to be
> destroyed.
>
> Meanwhile, the main thread is blocked from reading the queue until the
> lock is released (line 46). Following that it does one more yield
> (line 48) to allow for the thread to be destroyed before itself
> exiting.
>
> Do you have any evidence that indicates the main thread exits before
> the detached thread is destroyed?
>
> > This [main thread exiting with detached threads] causes perl to skip
> > global
> > destruction.
>
> I am not aware that this is the case. Can you provide
> documentation/evidence regarding this?
Add the following to your test just above the exit(0)
{
package foo;
sub DESTROY {
print "Global Destruction thread: " . threads->tid . "\n";
};
}
our $foo = bless {}, 'foo';
The message will never print. However if you change the test so that you save the thread, and call ->join on it before the exit, then the message will print.
Yesterday on #p5p several of us were discussing it. We noticed the problem because the perl test suite was not cleaning up all its temp files, this test is one of the culprits. Eventually we had to dive into thread code and confirm there is (intentional!!) code to block global destruction if there are running detached threads.
When we change this test to join on the thread instead of detach the leak stops.
Test2 (the new Test-Simple) uses temp files for threaded code, and we noticed it's destruction never occurred for this test, which is why there are temp files being left behind.