develooper Front page | perl.perl5.porters | Postings from January 2004

Thread::Bless problem simplified

Thread Next
From:
Elizabeth Mattijsen
Date:
January 9, 2004 07:34
Subject:
Thread::Bless problem simplified
Message ID:
p05111b04bc2479221278@[192.168.56.3]
Ok, I've managed to simplify the problem:

=== bug =============================================
use threads;
use Scalar::Util qw(weaken);

my $object = bless {},'Foo';
weaken( my $other = $object );

eval {
     threads->new( sub { 1 } )->join;
};

sub Foo::DESTROY { warn "DESTROY called with @_\n" }
=====================================================

Running this under valgrind gives:

=====================================================
$ valgrind perl5.8.3-threaded-debug bug
==389== Memcheck, a.k.a. Valgrind, a memory error detector for x86-linux.
==389== Copyright (C) 2002-2003, and GNU GPL'd, by Julian Seward.
==389== Using valgrind-2.0.0, a program supervision framework for x86-linux.
==389== Copyright (C) 2000-2003, and GNU GPL'd, by Julian Seward.
==389== Estimated CPU clock rate is 2814 MHz
==389== For more details, rerun with: -v
==389==
DESTROY called with Foo=HASH(0x4157ad58)
==389== valgrind's libpthread.so: KLUDGED call to: siglongjmp 
(cleanup handlers are ignored)
DESTROY called with Foo=HASH(0x41da5508)
==389== Invalid read of size 4
==389==    at 0x811668D: Perl_die_where (pp_ctl.c:1338)
==389==    by 0x80BECCA: Perl_vcroak (util.c:1195)
==389==    by 0x80BEE12: Perl_croak (util.c:1243)
==389==    by 0x80E8BC4: S_sv_del_backref (sv.c:4921)
==389==    Address 0x0 is not stack'd, malloc'd or free'd
Segmentation fault
=====================================================

Alternately, without the eval{}...

=== bug =============================================
use threads;
use Scalar::Util qw(weaken);

my $object = bless {},'Foo';
weaken( my $other = $object );

threads->new( sub { 1 } )->join;

sub Foo::DESTROY { warn "DESTROY called with @_\n" }
=====================================================

... there is a panic error but no segfault and no valgrind errors:

=====================================================
$ valgrind perl5.8.3-threaded-debug bug
==400== Memcheck, a.k.a. Valgrind, a memory error detector for x86-linux.
==400== Copyright (C) 2002-2003, and GNU GPL'd, by Julian Seward.
==400== Using valgrind-2.0.0, a program supervision framework for x86-linux.
==400== Copyright (C) 2000-2003, and GNU GPL'd, by Julian Seward.
==400== Estimated CPU clock rate is 2822 MHz
==400== For more details, rerun with: -v
==400==
DESTROY called with Foo=HASH(0x4157ad58)
==400== valgrind's libpthread.so: KLUDGED call to: siglongjmp 
(cleanup handlers are ignored)
DESTROY called with Foo=HASH(0x4229fd20)
panic: del_backref during global destruction.
==400==
==400== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 1)
==400== malloc/free: in use at exit: 1090588 bytes in 13347 blocks.
==400== malloc/free: 29486 allocs, 16139 frees, 14387929 bytes allocated.
==400== For a detailed leak analysis,  rerun with: --leak-check=yes
==400== For counts of detected errors, rerun with: -v
=====================================================


Hope this helps.


Liz

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About