[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] weird FFI callbacks
From: |
Thomas Chust |
Subject: |
Re: [Chicken-users] weird FFI callbacks |
Date: |
Thu, 31 Mar 2011 14:06:15 +0200 |
2011/3/31 Tomtom <address@hidden>:
> [...]
> quick summary: a jack client have to set a callback so the jack
> server can call it when the client is supposed to do
> something. Here, the callback call is supposed to trigger some
> scheme code execution.
> [...]
Hello,
the problem is that callbacks only work if the call from C to Scheme
happens in the dynamic scope of a call from Scheme to C that uses a
foreign-safe-lambda. Anything else is bound to break.
If you have C code that calls registered callbacks at random points in
time, perhaps even on a different thread, you're out of luck. I don't
know the jack API, but your example hints that either jack_activate
should be a foreign-safe-lambda that never returns until some main
loop is terminated, or you *are* out of luck.
Your only option in the out of luck situation is not to use regular
callbacks at all but to implement a sort of in-process remote
procedure call system where a C stub registered as a callback
transfers call information to a Scheme thread, waits for a reply from
there and then returns. Needless to say, this can be relatively tricky
to implement.
Ciao,
Thomas
--
When C++ is your hammer, every problem looks like your thumb.
[Chicken-users] weird FFI callbacks, Tomtom, 2011/03/31