[gambit-list] Reentrant calling into Gambit object code
Marc Feeley
feeley at iro.umontreal.ca
Sat Oct 29 22:25:09 EDT 2005
On 8-Oct-05, at 4:33 PM, Marko Cetina wrote:
> I'd like to use Gambit-compiled object code from a multithreaded C
> application.
>
> However, I'm unsure if Gambit supports reentrant calling from
> multithreaded C code. Could anybody help me with this?
>
The C code produced by the Gambit-C compiler is not reentrant. Only
a single C thread may be running Scheme code at any given point. So
if you have multiple C threads that need to call into Scheme, you
need to protect the Scheme code with mutexes. Moreover, in a setting
where multiple C threads are calling Scheme code, you can't use call/
cc to save the continuation of C thread T1 and then have another C
thread (T2) invoke the continuation captured by T1.
I have considered extending the FFI so that it automatically adds
these mutexes (possibly enabled with some compile time flag). This
would simplify using Gambit in a multithreaded setting. The only
macro definitions in include/gambit.h that have to be changed are:
___BEGIN_SFUN(proc,decl)
___END_SFUN
___BEGIN_SFUN_VOID(proc)
___END_SFUN_VOID
___BEGIN_SFUN_SCMOBJ(proc)
___END_SFUN_SCMOBJ
The global mutex must be acquired by BEGIN_XXX and released by END_XXX .
Marc
More information about the Gambit-list
mailing list