while debugging the modperl problem with threads.pm and not realizing that the problem lies not in the perl_clone(), but in the fact that the app itself is threaded, I was trying to reproduce the problem with one perl interpreter and its clone as you can see in the program at the end.
In the test below I'm using a blead version of the threaded perl, perl -V is at the end.
What I've noticed is that if I don't preload 'threads.pm' before cloning:
% gcc -o clone test.c `perl -MExtUtils::Embed -e ccopts -e ldopts` -Wall -g -DPRELOAD=0
% ./clone
0
1
Attempt to free temp prematurely: SV 0x810b4e4 during global destruction.
Scalars leaked: 1
I get the perl_clone report that threads->self->tid is actually 1. But I haven't spawned any threads. Shouldn't it report 0 as its tid()?
if I compile with -DPRELOAD=1 (so the cloned perl doesn't load threads.pm), both perls report 0 as their tid.
Also I get these destruction problems/leakage report, which go away if I clone with CLONEf_KEEP_PTR_TABLE|CLONEf_COPY_STACKS contrary to what perlapi.pod's perl_clone entry suggesting to use only CLONEf_KEEP_PTR_TABLE. Is this a problem in my test program or in threads.pm?
Here is the test program:
#include <EXTERN.h> #include <perl.h>
EXTERN_C void xs_init (pTHX);
EXTERN_C void boot_DynaLoader (pTHX_ CV* cv);
EXTERN_C void
xs_init(pTHX)
{
char *file = __FILE__;
dXSUB_SYS;
/* DynaLoader is a special case */
newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
}#if PRELOAD == 0 #define LOAD "" #define TEST "require threads; print threads->self->tid;" #elif PRELOAD == 1 #define LOAD "require threads;" #define TEST "print threads->self->tid;" #endif
int main(int argc, char **argv, char **env)
{
char *embedding[] = { "", "-le", "0" };
dTHX;
PerlInterpreter *one_perl = perl_alloc();
PerlInterpreter *two_perl; aTHX = one_perl; PERL_SET_CONTEXT(aTHX);
perl_construct(one_perl); perl_parse(one_perl, xs_init, 3, embedding, (char **)NULL);
/* DynaLoader must be preloaded before perl_clone, if DynaLoader
* is to be required later */
eval_pv("require DynaLoader;", TRUE);
eval_pv(LOAD, TRUE); /* loaded only by the first perl */two_perl = perl_clone(one_perl, CLONEf_KEEP_PTR_TABLE);
eval_pv(TEST, TRUE);
aTHX = two_perl; PERL_SET_CONTEXT(aTHX);
eval_pv(TEST, TRUE); perl_destruct(two_perl);
perl_free(two_perl); perl_destruct(one_perl);
perl_free(one_perl);exit(0);
}
perl -V:
Summary of my perl5 (revision 5.0 version 9 subversion 0 patch 18699) configuration:
Platform:
osname=linux, osvers=2.4.19-16mdksmp, archname=i686-linux-thread-multi
uname='linux hope.stason.org 2.4.19-16mdksmp #1 smp fri sep 20 16:08:37 cest 2002 i686 unknown unknown gnulinux '
config_args='-des -Dprefix=/home/stas/perl/blead-ithread -Dusethreads -Doptimize=-g -Duseshrplib -Dusedevel'
hint=recommended, useposix=true, d_sigaction=define
usethreads=define useithreads=define usemultiplicity=define
useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
use64bitint=undef use64bitall=undef uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-aliasing -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
optimize='-g',
cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-aliasing -I/usr/include/gdbm'
ccversion='', gccversion='3.2 (Mandrake Linux 9.0 3.2-1mdk)', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
alignbytes=4, prototype=define
Linker and Libraries:
ld='cc', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib
libs=-lnsl -lgdbm -ldb -ldl -lm -lpthread -lc -lcrypt -lutil -lrt
perllibs=-lnsl -ldl -lm -lpthread -lc -lcrypt -lutil -lrt
libc=/lib/libc-2.3.1.so, so=so, useshrplib=true, libperl=libperl.so
gnulibc_version='2.3.1'
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic -Wl,-rpath,/home/stas/perl/blead-ithread/lib/5.9.0/i686-linux-thread-multi/CORE'
cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'
Characteristics of this binary (from libperl):
Compile-time options: DEBUGGING MULTIPLICITY USE_ITHREADS USE_LARGE_FILES PERL_IMPLICIT_CONTEXT
Locally applied patches:
DEVEL18374
Built under linux
Compiled at Feb 14 2003 11:11:11
@INC:
/home/stas/perl/blead-ithread/lib/5.9.0/i686-linux-thread-multi
/home/stas/perl/blead-ithread/lib/5.9.0
/home/stas/perl/blead-ithread/lib/site_perl/5.9.0/i686-linux-thread-multi
/home/stas/perl/blead-ithread/lib/site_perl/5.9.0
/home/stas/perl/blead-ithread/lib/site_perl
.
__________________________________________________________________ Stas Bekman JAm_pH ------> Just Another mod_perl Hacker http://stason.org/ mod_perl Guide ---> http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
