[plt-scheme] Re: Using LibFFI along with threads

From: Hans Oesterholt-Dijkema (hdnews at gawab.com)
Date: Tue Jul 17 05:33:42 EDT 2007

Hi Tom,

That's exactly what I want. PLT Scheme (DrScheme,MzScheme)
doesn't do OS threads. In real life this means that a call to a
native C function will block your entire scheme language
including all "threads" in scheme.

Imagin a long database query blocking all your threads, or
a inserter thread doing inserts on a database, blocking your
entire user interface.

What I want is to do a "non blocking" call to a C function, by
starting the C function in an OS thread and let the current scheme
thread wait for the result, while allowing other scheme threads
to run. I've done this trick already in the past, but without the
FFI. However, it needs a littlebit of C code that must be compiled,
and the goal of using the ffi is to allow for native C bindings
without the need to compile glue code.

I've looked into the foreign code of PLT Scheme yesterday and I
think it is actually extremely easy to allow for a non blocking
ffi call, that only blocks the current scheme thread, but no others.

Maybe I'll propose a small code change in the foreign code of
PLT Scheme.


Op 17/7/2007 schreef "Tom Tromey" <tromey at redhat.com>:

>>>>>> "Hans" == Hans Oesterholt-Dijkema <hdnews at gawab.com> writes:
>Hans> Would it be possible to create an FFI object using libffi
>Hans> that is called from within a thread?
>I started looking at the source, but I think it would be simpler if
>you explained what you're trying to do.
>If you want to make a call via libffi and have the called function
>make a new thread, then make the real ffi call in that new thread --
>sure, this is possible.  You can pass CIFs and argument arrays around
>quite easily.

Posted on the users mailing list.