#! perl -slw use strict; use cback_test; use Inline C => Config => BUILD_NOISY => 1; use Inline C => <<'END_C', NAME => '_867652', CLEAN_AFTER_BUILD => 0; PerlInterpreter *saved1; SV *cback1; PerlInterpreter *saved2; SV *cback2; void cbProc1( unsigned int time ) { //this always returns "0" PerlInterpreter *temp = Perl_get_context(); printf( "Time in C-Callback1: %u. Prior ctx %lud\n", time , temp); PERL_SET_CONTEXT( saved1 ); { dSP; ENTER; SAVETMPS; PUSHMARK( SP ); XPUSHs( sv_2mortal( newSVuv( (UV)time ) ) ); PUTBACK; call_sv( cback1, G_DISCARD ); FREETMPS; LEAVE; } PERL_SET_CONTEXT( temp ); return; } void cbProc2( unsigned int time ) { //this always returns "0" PerlInterpreter *temp = Perl_get_context(); printf( "Time in C-Callback2: %u. Prior ctx %lud\n", time , temp); PERL_SET_CONTEXT( saved2 ); { dSP; ENTER; SAVETMPS; PUSHMARK( SP ); XPUSHs( sv_2mortal( newSVuv( (UV)time ) ) ); PUTBACK; //the error msg shows up after calling this call_sv( cback2, G_DISCARD ); FREETMPS; LEAVE; } PERL_SET_CONTEXT( temp ); return; } void* thread1( void *arg ) { int i=0; while( i++<5 ) { sleep( 5 ); printf( "Here in thread1..calling CCB1\n" ); cbProc1( time(NULL) ); } i=0; while( i++<5 ) { sleep( 5 ); printf( "Here in thread1..calling CCB2\n" ); cbProc2( time(NULL) ); } } void* thread2( void *arg ) { while( sleep( 7 ), 1 ) { printf( "Here in thread2\n" ); cbProc2( time(NULL) ); } } void setCallback1( SV* cv ) { pthread_t tid; //my code did not have the dTHX here, but adding it made no difference (i.e saved1 the same). //dTHX; //saved1 and saved2 are always the same too. saved1 = Perl_get_context(); cback1 = cv; printf("saved1 = %lud\n", saved1); // Start callback timer thread pthread_create( &tid, NULL, thread1, NULL ); return; } void setCallback2( SV* cv ) { pthread_t tid; //my code did not have the dTHX here, but adding it made no difference (i.e saved2 is the same). //dTHX; saved2 = Perl_get_context(); cback2 = cv; printf("saved2 = %lud\n", saved2); // Start callback timer thread //pthread_create( &tid, NULL, thread2, NULL ); return; } END_C $|++; print "Setting callback1..\n"; #Registering cback rhis gives a coredump or one or several other errors #when CCB calls PCB #setCallback1(\&cback_test::callback1); #this syntax works as expected in this program, but this doesnt #work (the pcb ref is not valid or null) when my typemap using SWIG runs setCallback1('cback_test::callback1'); while ($cback_test::cb1_cnt != 4) { print "Waiting for callback1 to finish..\n"; sleep(1); } print "Setting callback2..\n"; setCallback2(\&cback_test::callback2); while ($cback_test::cb2_cnt != 4) { print "Waiting for callback2 to finish..\n"; sleep(1); } sleep (15); __END__