Document handling of callbacks from foreign threads

Bug #622256 reported by Luís Oliveira
16
This bug affects 3 people
Affects Status Importance Assigned to Milestone
CFFI
Triaged
Wishlist
Unassigned

Bug Description

Calls to functions defined via cffi:defcallback coming from foreign threads (i.e., threads not created by the Lisp implementation) is not supported in all Lisps.

Clozure CL, for example, seems to this automagically. Gary Byers described the issue
in detail in this message
<http://www.clozure.com/pipermail/openmcl-devel/2003-May/004781.html>.
Although he says "that code isn't written yet", apparently it has been
written since then.

Here's a quick test to check whether your Lisp supports callbacks from
random threads.

(in-package :cffi)

(load-foreign-library "libpthread.so.0")

(defcallback foo :pointer ((arg :pointer))
 (declare (ignore arg))
 (print 'called-into-lisp-from-foreign-thread)
 (null-pointer))

(defctype pthread-t :unsigned-long)

(with-foreign-object (th 'pthread-t)
 (foreign-funcall "pthread_create" :pointer th :pointer (null-pointer)
                  :pointer (callback foo) :pointer (null-pointer))
 (foreign-funcall "pthread_join" pthread-t (mem-ref th 'pthread-t)
                  :pointer (null-pointer)))

We should at some point run it on the supported Lisps and note down
which ones support this. Then add that information to the manual and
possibly push something informative to *FEATURES* on Lisps that don't
support this.

Tags: callbacks
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.