Thanks Zwon,

I had not created any interpreter (perl_alloc) in the thread earlier. I now tried this and it still fails/seg faults inside call_sv(). I'm still trying to understand if I need perl_parse and if I should do a perl_clone rather than perl_alloc. Also, unclear if there is any "locking"/mutual exclusion between the two interpreters required before invoking call_sv

Are there any other forums with more experience in this that I should post at?

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

In reply to Re^2: my_perl is NULL when embed perl in C ; "dSP" segmentation faults by perlmonk1729
in thread Working with multiple interpreters (my_perl is NULL when embed perl in C ; "dSP" segmentation faults) by perlmonk1729

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.