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?
Thanks a lot, Marko Cetina
_________________________________________________________________ Dont just search. Find. Check out the new MSN Search! http://search.msn.click-url.com/go/onm00200636ave/direct/01/
Afficher les réponses par date
On 10/8/05, Marko Cetina golubarnik@hotmail.com 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?
I don't know this for sure, but having looked at the code I'm pretty certain that you need to put a mutex around all calls into Gambit functions.
AGL
-- Adam Langley agl@imperialviolet.org http://www.imperialviolet.org 650-283-6941
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