On 2011-05-23, at 3:40 PM, Roger Wilson wrote:
> I'm evaluating using Gambit-C Scheme as a scripting type language within my application. The main app is written in C++ and I've got the C++ -> Scheme -> C++ calls all working. That was all straightforward and I'm pretty happy with that. I'm now trying to integrate swank and have hit a bit of a dead end. I can run swank-gambit on its own and it just worked, the problem has come trying to run it alongside the thread that communicates with the host C++ app. I've tried replacing the code at the bottom of swank-gambit.scm with the following based on the iOS sample. This creates a new thread that returns to the C++ host, while the primordial thread creates the swank server.
>
> (continuation-capture
> (lambda (cont)
> (thread-start!
> (make-thread
> (lambda ()
> (continuation-return cont #f))))
>
> ;; the primordial thread is running this...
> (swank-server-register!)
> (thread-sleep! +inf.0)
>
> exit)))
>
>
> That works in as much as it creates the tcp listen port and slime can connect to it, however it seems that the connection is rarely if ever serviced. The calls between C++ and Scheme in the other thread all continue ok. Can someone point me in the direction I need to fix this please? I suspect I've got a fundamentally wrong understanding of swank or the whole Gambit threading model. Do I somehow need to provide execution time to the primordial thread?
>
> Roger.
Gambit implements green threads, and this may be the cause of your problem. If you use the FFI to call a C++ function that blocks, or if your main function in C++ blocks and only calls the Scheme code occasionally (for example when there is a GUI event), then the context switching of the Scheme threads will not happen and your Scheme threads will not get to run (even if they are conceptually runnable).