Mailing List Archive

[perl #100840] DESTROY called twice on objects created in threads
# New Ticket Created by "Jerry D. Hedden"
# Please include the string: [perl #100840]
# in the subject line of all future correspondence about this issue.
# <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=100840 >


This is a bug report for perl from jdhedden@cpan.org,
generated with the help of perlbug 1.39 running under perl 5.10.1.

-----------------------------------------------------------------
[Please describe your issue here]

The bug is that when a thread creates an object and then
exits, the object's DESTROY method is being called twice:
First in the thread where it was created, and then again in
the main thread.

In contrast, if the object is destroyed before the thread
exits (for example, undef($obj)), DESTROY is only called
once (as should be the case).

The attached script demonstrates this above. Here is the output:

Object created in thread 1
Okay: Object created in thread 1 was destroyed in thread 1
BUG: Object created in thread 1 but destroyed in thread 0

Object created in thread 2
Okay: Object created in thread 2 was destroyed in thread 2

This occurs in all versions of the threads module (1.09 -
1.85) that I tested with this version of Perl (5.10.1 under
Cygwin on Windows).

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
category=library
severity=high
module=threads
---
Site configuration information for perl 5.10.1:

Configured by rurban at Sat Aug 28 20:14:06 CEST 2010.

Summary of my perl5 (revision 5 version 10 subversion 1) configuration:

Platform:
osname=cygwin, osvers=1.7.5(0.22553),
archname=i686-cygwin-thread-multi-64int
uname='cygwin_nt-5.1 reini 1.7.5(0.22553) 2010-04-12 19:07 i686 cygwin '
config_args='-de -Dlibperl=cygperl5_10.dll -Dcc=gcc-4 -Dld=g++-4
-Dmksymlinks -Dusethreads -Dmad=y -Doptimize=-O3 -Accflags=-g3'
hint=recommended, useposix=true, d_sigaction=define
useithreads=define, usemultiplicity=define
useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
use64bitint=define, use64bitall=undef, uselongdouble=undef
usemymalloc=y, bincompat5005=undef
Compiler:
cc='gcc-4', ccflags ='-DPERL_USE_SAFE_PUTENV -U__STRICT_ANSI__ -g3
-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include',
optimize='-O3',
cppflags='-DPERL_USE_SAFE_PUTENV -U__STRICT_ANSI__ -g3
-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
ccversion='', gccversion='4.3.4 20090804 (release) 1', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
ivtype='long long', ivsize=8, nvtype='double', nvsize=8,
Off_t='off_t', lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries:
ld='g++-4', ldflags =' -Wl,--enable-auto-import
-Wl,--export-all-symbols -Wl,--stack,8388608
-Wl,--enable-auto-image-base -fstack-protector -L/usr/local/lib'
libpth=/usr/local/lib /usr/lib /lib
libs=-lgdbm -ldb -ldl -lcrypt -lgdbm_compat
perllibs=-ldl -lcrypt
libc=/usr/lib/libc.a, so=dll, useshrplib=true, libperl=cygperl5_10.dll
gnulibc_version=''
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
cccdlflags=' ', lddlflags=' --shared -Wl,--enable-auto-import
-Wl,--export-all-symbols -Wl,--stack,8388608
-Wl,--enable-auto-image-base -L/usr/local/lib -fstack-protector'

Locally applied patches:
CYG11 no-bs
CYG12 no archlib in otherlibdirs
CYG14 Dynaloader
CYG15 static-Win32CORE
CYG17 utf8-paths
CYG21 LibList-Kid.patch
CYG22 cygwin-1.7 hints
CYG23 544-stat
CYG24 build man pages
CYG25 rebase_privlib
Module-Build-0.36_13
Bug#55162 CYG18 File::Spec::case_tolerant performance
disable ExtUtils::MakeMaker::Coverage in Sys-Syslog

---
@INC for perl 5.10.1:
/usr/lib/perl5/5.10/i686-cygwin
/usr/lib/perl5/5.10
/usr/lib/perl5/site_perl/5.10/i686-cygwin
/usr/lib/perl5/site_perl/5.10
/usr/lib/perl5/vendor_perl/5.10/i686-cygwin
/usr/lib/perl5/vendor_perl/5.10
/usr/lib/perl5/vendor_perl/5.10
/usr/lib/perl5/site_perl/5.8
/usr/lib/perl5/vendor_perl/5.8
.

---
Environment for perl 5.10.1:
CYGWIN=nodosfilewarning
HOME=/home/heddenj
LANG=C
LANGUAGE=C
LC_ALL=C
LD_LIBRARY_PATH=/usr/local/lib:/usr/lib
LOGDIR (unset)
PATH=/home/heddenj/bin:/usr/local/src/perl/bin:/usr/local/bin:/usr/bin:/c/Progra~1/Java/jre6/bin:/c/WINDOWS/system32:/c/WINDOWS:/c/WINDOWS/System32/Wbem:/c/Program
Files/ATI Technologies/ATI.ACE/Core-Static:/c/Program
Files/TortoiseSVN/bin:/c/PYTHON27:/c/Program Files/MySQL/MySQL Server
5.5/bin:/c/WINDOWS/system32/WindowsPowerShell/v1.0:.
PERLIO=perlio
PERL_BADLANG (unset)
SHELL (unset)
Re: [perl #100840] DESTROY called twice on objects created in threads [ In reply to ]
sub func {
my $obj = Foo->new();
}

is functionally the same as

sub func {
return my $obj = Foo->new();
}

which is effectively the same as

sub func {
return Foo->new();
}

In order for join() to return this value, it needs to be cloned. $obj gets
cloned, the original gets destroyed, and the clone is returned by join()
where it is destroyed. Fix:

sub func {
my $obj = Foo->new();
1;
}

This isn't a bug.