Maybe this will explain the save&restore and context caching mechanism better than I've achieved using words:

#! perl -slw use strict; use Inline C => Config => BUILD_NOISY => 1; use Inline C => <<'END_C', NAME => '_867652', CLEAN_AFTER_BUILD => 0; PerlInterpreter *saved; SV *callback; VOID CALLBACK cbProc( DWORD time ) { PerlInterpreter *temp = Perl_get_context(); printf( "C-Callback: %u\n", time ); PERL_SET_CONTEXT( saved ); { dSP; ENTER; SAVETMPS; PUSHMARK( SP ); XPUSHs( sv_2mortal( newSVuv( (UV)time ) ) ); PUTBACK; call_sv( callback, G_DISCARD ); FREETMPS; LEAVE; } PERL_SET_CONTEXT( temp ); return; } void __cdecl thread( VOID *arg ) { while( Sleep( 5000 ), 1 ) { printf( "Here\n" ); cbProc( GetTickCount() ); } } void setCallback( SV* cv ) { dTHX; saved = Perl_get_context(); callback = cv; // Start callback timer thread _beginthread( &thread, 0, NULL ); return; } END_C $|++; sub callback { print "Timer value is: $_[0]"; return; } setCallback( 'callback' ); sleep 100; __END__ C:\test>867652 Here C-Callback: 1355573480 Timer value is: 1355573480 Here C-Callback: 1355578472 Timer value is: 1355578472 Here C-Callback: 1355583479 Timer value is: 1355583479 Terminating on signal SIGINT(2)

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
RIP an inspiration; A true Folk's Guy

In reply to Re^9: Perl crash during perl_clone by BrowserUk
in thread Perl crash during perl_clone 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.