Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DESTROY called twice on objects created in threads #11686

Closed
p5pRT opened this issue Oct 6, 2011 · 5 comments
Closed

DESTROY called twice on objects created in threads #11686

p5pRT opened this issue Oct 6, 2011 · 5 comments

Comments

@p5pRT
Copy link

p5pRT commented Oct 6, 2011

Migrated from rt.perl.org#100840 (status was 'rejected')

Searchable as RT100840$

@p5pRT
Copy link
Author

p5pRT commented Oct 6, 2011

From @jdhedden

Created by @jdhedden

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).

Perl Info

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)

@p5pRT
Copy link
Author

p5pRT commented Oct 6, 2011

From @jdhedden

bug.pl

@p5pRT
Copy link
Author

p5pRT commented Oct 6, 2011

From @ikegami

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.

@p5pRT
Copy link
Author

p5pRT commented Oct 6, 2011

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Nov 6, 2011

@cpansprout - Status changed from 'open' to 'rejected'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant