[cffi-devel] Threads and function pointers misunderstanding

Benjamin Tovar mugrido at gmail.com
Sun May 10 20:37:13 UTC 2009


Hi,

I am writing an application that creates a callback in lisp
(cffi:defcallback callback-lisp ...), and then passes the pointer to a C
library with something like (set-callback-in-c (cffi:callback
callback-lisp). In C, I assign the function pointer as follows:

/* global variable */
void (*callback)(void);

void set_callback_in_c(void (*callback_from_lisp)(void))
{
  callback = callback_from_lisp;
}

And call (*callback)()); as needed.

Now, everything works nicely, unless I use threads in C (pthreads). With
threads, the first time I call (*callback)()); it segfaults, as if the
pointer to the function was not valid (it does get assigned). I have no
clue of what is going on, since it seems that the threads are not
sharing the information to the function pointer. What I am missing here?
I have tried with both Allegro and SBCL, on a Debian "testing".

Thanks!






More information about the cffi-devel mailing list