[Ecls-list] Multi thread problem

Stanislav Frolov frolosofsky at gmail.com
Wed Sep 26 12:34:54 UTC 2012


Hi. I use latest version of ECL from git and try to call lisp code in 
different threads.

The following code fails (sigsegv) inside ecl_import_current_thread.

#include<ecl/ecl.h>
#include<pthread.h>
#include<unistd.h>
#include<stdio.h>

void *thread_foo(void *p){
 (void)p;
 printf("--1\n"); /* print 5 times */
 ecl_import_current_thread(Cnil,Cnil);
 printf("--2\n"); /* no prints */
 int i=0;
 for(;i<3;i++){
  sleep(1);
  printf("%d\n",i);}
 ecl_release_current_thread();
 return 0;}


int main(int argc,char **argv){
 cl_boot(argc,argv);
 
 pthread_t thr[5];
 int i;
 for(i=0;i<sizeof(thr)/sizeof(*thr);i++){
  pthread_create(&thr[i],0,thread_foo,0);}

 for(i=0;i<sizeof(thr)/sizeof(*thr);i++){
  pthread_join(thr[i],0);}
 return 0;}

The same code without any ecl calls (cl_boot, ecl_make.., ecl_release..) works 
fine.

What am I doing wrong? How to call lisp code in few threads?




More information about the ecl-devel mailing list