It took a lot of effort to make this compile under Debian, so for those less fortunate (or patient) than I, here's the output:// see perldoc perlembed (http://www.perldoc.com/perl5.8.0/pod/perlemb +ed.html) #include <EXTERN.h> #include <perl.h> #include <pthread.h> // pthreads: http://www.cs.nmsu.edu/~jcook/Tools/pthreads/pthreads.htm +l #include <pthread.h> #include <signal.h> #include <stdlib.h> #include <unistd.h> const char perlscript[] = "#line 1 \"fake.pl\"\n" "$SIG{INT} = sub { die 'interrupted' };\n" "for (1..10) {\n" " print qq[thread $_...\\n];\n" " sleep(1);\n" "}\n"; // pthreads: http://www.cs.nmsu.edu/~jcook/Tools/pthreads/pthreads.htm +l // http://www.llnl.gov/computing/tutorials/workshops/workshop/pthreads +/MAIN.html void* thread(void *arg) { char *perlargs[] = { "", "-e0" }; static PerlInterpreter *my_perl; // I tried naming this 'perl' +but PL_exit_flags was unwilling // taken nearly verbatim from perlembed my_perl = perl_alloc(); perl_construct(my_perl); PL_exit_flags |= PERL_EXIT_DESTRUCT_END; perl_parse(my_perl, NULL, 2, perlargs, (char**)NULL); perl_run(my_perl); eval_pv(perlscript, TRUE); perl_destruct(my_perl); perl_free(my_perl); return NULL; } int main(int argc, char *argv[]) { pthread_t tid; printf("creating new thread...\n"); pthread_create(&tid, NULL, thread, NULL); sleep(5); pthread_kill(tid, SIGINT); pthread_join(tid, NULL); }
creating new thread... thread 1... thread 2... thread 3... thread 4... thread 5... interrupted at fake.pl line 1.
$"=$,,$_=q>|\p4<6 8p<M/_|<('=> .q>.<4-KI<l|2$<6%s!<qn#F<>;$, .=pack'N*',"@{[unpack'C*',$_] }"for split/</;$_=$,,y[A-Z a-z] {}cd;print lc
In reply to Interrupting Perl from another thread under Win32 by Stevie-O
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |