|
From: | Neil Jerram |
Subject: | Re: Protecting C code from continuations |
Date: | Mon, 05 Jul 2004 23:31:04 +0100 |
User-agent: | Mozilla/5.0 (X11; U; Linux 2.4.4-4GB i686; en-US; 0.8.1) Gecko/20010515 |
Steve Tell wrote:
On Sun, 4 Jul 2004, Neil Jerram wrote:Hi all, I'm working with some C code that is not continuation-safe; [...] Any comments/ideas?Might (call-with-dynamic-root thunk) be what you want?
Thanks for reminding me - I had forgotten about call-with-dynamic-root (cwdr). However, I'm not sure that it gives me what I need, because I believe that a continuation captured within one cwdr cannot then be invoked within a different cwdr.
To explain further: in my program, the main loop is in C; some events from the main loop are handled purely within C code, while others are dispatched into Scheme. The way I want to use continuations is such that a Scheme coder can write
(begin (do-thing-1) (do-thing-2) (do-thing-3))without having to worry about the fact that (do-thing-2) will usually have to escape and then let the C main loop run for a few iterations until the information needed to complete (do-thing-2) comes back.
So, the continuation to "finish (do-thing-2) and then continue" needs to be captured within one call from C into Scheme, but invoked within some later call from C into Scheme (not necessarily the next such call).
Obviously (I think!) I can implement this using CPS (continuation-passing style), and then define convenience macros to try to hide the CPS, but it would be much nicer to use real continuations if that is possible.
Regards, Neil
[Prev in Thread] | Current Thread | [Next in Thread] |