Subject: | problem when using threads/threading (might be XS related) |
Hi,
In a rather complex Moose-based system we started using
Perl threading in one sub-module. We get a segmentation
faults which I was able to track down to MooseX::Method::Signatures.
Attached a simple test case that fails. Sometimes segmentation
fault. In worst case the process has a recursion and is hard
to stop (kill -9).
The sampling graph comes from the MacOS 10.6 Activity Monitor. I
think it's the equivalent of dtrace/strace.
You see the recursion happen inside an XS module. I'm
aware that for better performance some functions are now
implemented in C. I'm using method signatures whenever I
can so I'm glad that's the case.
Some testing has shows that of all types
http://search.cpan.org/perldoc?Moose::Util::TypeConstraints
only ArrayRef[], HashRef[], Maybe[] are affected.
Attached also the work-around we're using right now: we
define a custom subtype in a separate class (we had a
special OurApplication::MooseTypes class anyway). I think
it works because the XS code is not called. It works even
for Maybe[Arrayref[HashRef[some::class]]]
thanks for all!
marc tobias
Subject: | threads_and_signatures.workaround.t |
use strict;
use feature qw(say);
use threads;
###################################
## ... adding this ...
##
use MooseX::Types -declare => [qw(ArrayRefOfInt)];
use MooseX::Types::Moose qw(ArrayRef Int);
BEGIN {
subtype ArrayRefOfInt,
as ArrayRef[Int];
}
##
###################################
use MooseX::Method::Signatures;
method mysub (ArrayRefOfInt :$ra_numbers){
# do something
}
foreach (1..2){
threads->create( sub { say "doing nothing." } );
}
foreach (threads->list){
$_->join;
}
say "finished";
Subject: | perl-version.txt |
Summary of my perl5 (revision 5 version 10 subversion 0) configuration:
Platform:
osname=darwin, osvers=10.0, archname=darwin-thread-multi-2level
uname='darwin neige.apple.com 10.0 darwin kernel version 10.0.0d8: tue may 5 19:29:59 pdt 2009; root:xnu-1437.2~2release_i386 i386 '
config_args='-ds -e -Dprefix=/usr -Dccflags=-g -pipe -Dldflags= -Dman3ext=3pm -Duseithreads -Duseshrplib -Dinc_version_list=none -Dcc=gcc-4.2'
hint=recommended, useposix=true, d_sigaction=define
useithreads=define, usemultiplicity=define
useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
use64bitint=define, use64bitall=define, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='gcc-4.2', ccflags ='-arch x86_64 -arch i386 -arch ppc -g -pipe -fno-common -DPERL_DARWIN -fno-strict-aliasing -I/usr/local/include',
optimize='-Os',
cppflags='-g -pipe -fno-common -DPERL_DARWIN -fno-strict-aliasing -I/usr/local/include'
ccversion='', gccversion='4.2.1 (Apple Inc. build 5646)', gccosandvers=''
intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries:
ld='gcc-4.2 -mmacosx-version-min=10.6', ldflags ='-arch x86_64 -arch i386 -arch ppc -L/usr/local/lib'
libpth=/usr/local/lib /usr/lib
libs=-ldbm -ldl -lm -lutil -lc
perllibs=-ldl -lm -lutil -lc
libc=/usr/lib/libc.dylib, so=dylib, useshrplib=true, libperl=libperl.dylib
gnulibc_version=''
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
cccdlflags=' ', lddlflags='-arch x86_64 -arch i386 -arch ppc -bundle -undefined dynamic_lookup -L/usr/local/lib'
Characteristics of this binary (from libperl):
Compile-time options: MULTIPLICITY PERL_DONT_CREATE_GVSV
PERL_IMPLICIT_CONTEXT PERL_MALLOC_WRAP USE_64_BIT_ALL
USE_64_BIT_INT USE_ITHREADS USE_LARGE_FILES
USE_PERLIO USE_REENTRANT_API
Locally applied patches:
/Library/Perl/Updates/<version> comes before system perl directories
installprivlib and installarchlib points to the Updates directory
Built under darwin
Compiled at Jun 24 2009 00:35:27
%ENV:
PERL5LIB="/sw/lib/perl5:/sw/lib/perl5/darwin"
@INC:
/sw/lib/perl5
/sw/lib/perl5/darwin
/Library/Perl/Updates/5.10.0
/System/Library/Perl/5.10.0/darwin-thread-multi-2level
/System/Library/Perl/5.10.0
/Library/Perl/5.10.0/darwin-thread-multi-2level
/Library/Perl/5.10.0
/Network/Library/Perl/5.10.0/darwin-thread-multi-2level
/Network/Library/Perl/5.10.0
/Network/Library/Perl
/System/Library/Perl/Extras/5.10.0/darwin-thread-multi-2level
/System/Library/Perl/Extras/5.10.0
.
Subject: | threads_and_signatures.fails.t |
use strict;
use feature qw(say);
use threads;
use MooseX::Method::Signatures;
method mysub (ArrayRef[Int] :$ra_numbers){
# do something
}
foreach (1..2){
threads->create( sub { say "doing nothing." } );
}
foreach (threads->list){
$_->join;
}
say "finished";
Subject: | process_sample_macos.txt |
Sampling process 51221 for 3 seconds with 1 millisecond of run time between samples
Sampling completed, processing symbols...
Analysis of sampling perl5.10.0 (pid 51221) every 1 millisecond
Call graph:
2739 Thread_22493941 DispatchQueue_1: com.apple.main-thread (serial)
2739 start
2739 main
2739 perl_run
2739 Perl_runops_standard
2739 Perl_pp_entersub
2739 XS_threads_join
2739 S_ithread_clear
2739 perl_destruct
2739 Perl_sv_clean_objs
2739 Perl_sv_add_arena
2739 Perl_sv_free2
2739 Perl_sv_clear
2739 Perl_hv_undef
2739 Perl_hv_iterinit
2739 Perl_hv_free_ent
2739 Perl_sv_free2
2739 Perl_sv_clear
2739 Perl_sv_free2
2739 Perl_sv_clear
2739 Perl_hv_undef
2739 Perl_hv_iterinit
2739 Perl_hv_free_ent
2739 Perl_sv_free2
2739 Perl_sv_clear
2739 Perl_sv_free2
2739 Perl_sv_clear
2739 Perl_hv_undef
2739 Perl_hv_iterinit
2739 Perl_hv_free_ent
2739 Perl_sv_free2
2739 Perl_sv_clear
2739 Perl_sv_free2
2739 Perl_sv_clear
2739 Perl_hv_undef
2739 Perl_hv_iterinit
2739 Perl_hv_free_ent
2739 Perl_sv_free2
2739 Perl_sv_clear
2739 Perl_sv_free2
2739 Perl_sv_clear
2739 Perl_hv_undef
2739 Perl_hv_iterinit
2739 Perl_hv_free_ent
2739 Perl_sv_free2
2739 Perl_sv_clear
2739 Perl_sv_free2
2739 Perl_sv_clear
2739 Perl_av_undef
2739 Perl_sv_free2
2739 Perl_sv_clear
2739 Perl_sv_free2
2739 Perl_sv_clear
2739 Perl_hv_undef
2739 Perl_hv_iterinit
2739 Perl_hv_free_ent
2739 Perl_sv_free2
2739 Perl_sv_clear
2739 Perl_sv_free2
2739 Perl_sv_clear
2739 Perl_hv_undef
2739 Perl_hv_iterinit
2739 Perl_hv_free_ent
2739 Perl_sv_free2
2739 Perl_sv_clear
2739 Perl_sv_free2
2739 Perl_sv_clear
2739 Perl_mg_free
2739 Perl_sv_kill_backrefs
2739 Perl_sv_free2
2739 Perl_sv_clear
2739 Perl_mg_free
Total number in stack (recursive counted multiple, when >=5):
18 Perl_sv_clear
18 Perl_sv_free2
7 Perl_hv_free_ent
7 Perl_hv_iterinit
7 Perl_hv_undef
Sort by top of stack, same collapsed (when >= 5):
Perl_mg_free 2739
Sample analysis of process 51221 written to file /dev/stdout