ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl-mod_perl
perl-mod_perl
Using multiple perl interpreters
by Sri other posts by this author
Nov 4 2009 8:49PM messages near this date
Re: Best Practices for managing repetitive Apache config file entries? | Re: Using multiple perl interpreters
Hi,

I've read several posts on this forum on similar topic, but not able to figure out the probl
em in my specific case. So hoping someone can help me here.  Essentially, its a seg fault wh
en using a thread-specific interpreter.

I'm trying to provide a Perl interface to a C library (event-driven).  The C library has API
s, ofcourse, but it also allows perl-subroutines to be registered as callbacks into the C li
brary.  The C library has a thread that monitors external events and invokes the perl-sub ca
llbacks.

The default perl interpreter is executing the script (interpreter instance one).  I do NOT h
ave any code to create/initiaze this instance in my api wrappers.   My library's thread, cre
ates a new interpreter.  But, crashes in the call_sv().  If I execute the same code (call_ha
ndler below, unmodified) as part of an API call invoked from perl-script, it works just fine
.  So, I feel I'm not initializing/using the 2nd instance correctly or "coordinating" betwee
n the two instances properly.  If anyone has pointers or other forums that may specialize in
 this topic, it would be great help.

I tried to use perl_clone instead of perl_alloc, but that method crashed too.

---using perl 5.8.8, compiled with multiplicity, implicit context (see below)---

void mythread_fn(void)
{

         static PerlInterpreter *my_perl=NULL;

         my_perl = perl_alloc();
         PERL_SET_CONTEXT(my_perl);
         perl_construct(my_perl);
         perl_run(my_perl);

         while (1)
         {

             /* monitor for events */
             if (event == xyz)
                 callback_handler(event);
         }

        perl_destruct(my_perl);
        perl_free(my_perl);
}

void callback_handler(int event)
{
      dTHX;
      dSP;

      ENTER;
      SAVETMPS;

      SV * sv = disc_callback;  /* saved earlier in an API call */
      if (sv == (SV*)NULL)
         croak("Internal error...\n");

      PUSHMARK(SP);
      XPUSHs(sv_2mortal(newSViv(event)));
      PUTBACK;

      /* Call the Perl sub */
      call_sv(sv, G_DISCARD);  /* crashes as shown below in gdb */

      FREETMPS;
      LEAVE;
}

Part of gdb stacktrace.

#0  Perl_pp_entersub (my_perl=0x6587b0) at pp_hot.c:2945
#1  0x00000000004224f3 in S_call_body (my_perl=0x6587b0, myop=0x65a6e0,
    is_eval=1 '\001') at perl.c:2728
#2  0x00000000004223c4 in Perl_call_sv (my_perl=0x6587b0, sv=0x635420, flags=2)
    at perl.c:2607

parts from perl -V

    cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-stri
ct-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/inc
lude/gdbm',

Characteristics of this binary (from libperl):
  Compile-time options: DEBUGGING MULTIPLICITY PERL_IMPLICIT_CONTEXT
                        PERL_MALLOC_WRAP THREADS_HAVE_PIDS USE_64_BIT_ALL
                        USE_64_BIT_INT USE_ITHREADS USE_LARGE_FILES
                        USE_PERLIO USE_REENTRANT_API




      
Thread:
Sri
Sri

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved