A
Andreas Otto
Hi,
the following scenario:
I use perl (see below) and write an extension (perlmsgque) as wrapper for
an existing shared library (libmsgque).
everything works fine without threads:
now I add threads.
1) I want to use a new interpreter per thread
2) the new thread is created in the libmsgque shared library
3) after create the perl is initialized with
static enum MqErrorE FactoryCreate (
struct MqS * const tmpl,
enum MqFactoryE create,
MQ_PTR data,
struct MqS ** contextP
) {
if (create == MQ_FACTORY_NEW_THREAD) {
PERL_SET_CONTEXT (perl_clone ((PerlInterpreter*)tmpl->threadData, 0));
}
....
<<<<<<<<<<<<<<<<<<<<<<<<<
4) I use "perl_clone" the create the new interpreter as clone
from the existing one
6) create and setup was fine
7) but the first callback:
static enum MqErrorE
ProcCall (
struct MqS * const context,
MQ_PTR const data
)
{
dSP;
SV * method = (SV*) data;
enum MqErrorE ret = MQ_OK;
ENTER;
SAVETMPS;
PUSHMARK(SP);
XPUSHs((SV*)context->self);
PUTBACK;
call_sv (method, G_SCALAR|G_DISCARD|G_EVAL);
ret = ProcError (aTHX_ context, ERRSV);
FREETMPS;
LEAVE;
return ret;
}
<<<<<<<<<<<<<<<<<<<<<<<<<<<
create an error: the argument stack is empty and:
sub ServerSetup {
my $ctx = shift;
print "ctx<$ctx>\n";
....
<<<<<<<<<<<<<<<<<<<<<<<<<<<
says that "$ctx" is empty
so I come to the conclusion that "call_sv" and "stack" does not match
anymore. "context->self is not empty
Question
What can I do ?
PERL:
Platform:
osname=linux, osvers=2.6.27.29-0.1-default, archname=x86_64-linux-
thread-multi
uname='linux linux-522u 2.6.27.29-0.1-default #1 smp 2009-08-15 17:53:59
+0200 x86_64 x86_64 x86_64 gnulinux '
config_args='-des -Dprefix=/home/dev1usr/ext/x86_64-suse-linux/thread -
Dusethreads'
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='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe
-fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -
D_FILE_OFFSET_BITS=64',
optimize='-O2',
cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-
protector -I/usr/local/include'
ccversion='', gccversion='4.3.2 [gcc-4_3-branch revision 141291]',
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='cc', ldflags =' -fstack-protector -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib /lib64 /usr/lib64 /usr/local/lib64
libs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
libc=/lib/libc-2.9.so, so=so, useshrplib=false, libperl=libperl.a
gnulibc_version='2.9'
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib -fstack-
protector'
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
Built under linux
Compiled at Oct 2 2009 09:10:52
the following scenario:
I use perl (see below) and write an extension (perlmsgque) as wrapper for
an existing shared library (libmsgque).
everything works fine without threads:
now I add threads.
1) I want to use a new interpreter per thread
2) the new thread is created in the libmsgque shared library
3) after create the perl is initialized with
static enum MqErrorE FactoryCreate (
struct MqS * const tmpl,
enum MqFactoryE create,
MQ_PTR data,
struct MqS ** contextP
) {
if (create == MQ_FACTORY_NEW_THREAD) {
PERL_SET_CONTEXT (perl_clone ((PerlInterpreter*)tmpl->threadData, 0));
}
....
<<<<<<<<<<<<<<<<<<<<<<<<<
4) I use "perl_clone" the create the new interpreter as clone
from the existing one
6) create and setup was fine
7) but the first callback:
static enum MqErrorE
ProcCall (
struct MqS * const context,
MQ_PTR const data
)
{
dSP;
SV * method = (SV*) data;
enum MqErrorE ret = MQ_OK;
ENTER;
SAVETMPS;
PUSHMARK(SP);
XPUSHs((SV*)context->self);
PUTBACK;
call_sv (method, G_SCALAR|G_DISCARD|G_EVAL);
ret = ProcError (aTHX_ context, ERRSV);
FREETMPS;
LEAVE;
return ret;
}
<<<<<<<<<<<<<<<<<<<<<<<<<<<
create an error: the argument stack is empty and:
sub ServerSetup {
my $ctx = shift;
print "ctx<$ctx>\n";
....
<<<<<<<<<<<<<<<<<<<<<<<<<<<
says that "$ctx" is empty
so I come to the conclusion that "call_sv" and "stack" does not match
anymore. "context->self is not empty
Question
What can I do ?
PERL:
Summary of my perl5 (revision 5 version 10 subversion 1) configuration:perl -V
Platform:
osname=linux, osvers=2.6.27.29-0.1-default, archname=x86_64-linux-
thread-multi
uname='linux linux-522u 2.6.27.29-0.1-default #1 smp 2009-08-15 17:53:59
+0200 x86_64 x86_64 x86_64 gnulinux '
config_args='-des -Dprefix=/home/dev1usr/ext/x86_64-suse-linux/thread -
Dusethreads'
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='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe
-fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -
D_FILE_OFFSET_BITS=64',
optimize='-O2',
cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-
protector -I/usr/local/include'
ccversion='', gccversion='4.3.2 [gcc-4_3-branch revision 141291]',
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='cc', ldflags =' -fstack-protector -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib /lib64 /usr/lib64 /usr/local/lib64
libs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
libc=/lib/libc-2.9.so, so=so, useshrplib=false, libperl=libperl.a
gnulibc_version='2.9'
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib -fstack-
protector'
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
Built under linux
Compiled at Oct 2 2009 09:10:52