Serialized partial continuations
A suspension is a serialized partial continuation. This extension provides basic tools for working with suspensions and may be useful for implementing continuation-based modal behaviour in applications like web-servers.
Note that suspensions can only be reliably created for compiled code, as continuations created by the interpreter will contain more references to live data as needed - in particular the environment representation of the interpreter is simpler and retains more garbage. Continuations created by compiled code only reference the minimal set of live data required to continue execution and thus are much smaller.
Not all data is serializable, ports and foreign pointers are not, for example. To be able to create a suspension from a pending continuation, no references to such data may exist in the continuation (say, in local bindings which are accessed by code executed when the continuation is resumed).
The implementation of delimited execution contexts creates a separate thread so (current-thread) will not be eq? to the thread that created the delimited execution context. Parameters modified in the new execution context are propagated back to the parent thread, though. Also, any exceptions raised in the new context will be delivered to the parent thread.
The default ports (current-[input,output,error]-port) are bound to the default STDIO-ports during execution of a limited execution context.
- (with-limited-continuation THUNK) procedure
Creates a limited execution context by spawning a new thread and suspending the current one. THUNK should be a procedure of no arguments and will be executed in the new context. Any results returned by THUNK will be returned by the with-limited-continuation form.
- (continuation-drop . results) procedure
Exits the execution context created by the innermost enclosing with-limited-continuation form and returns RESULTS ... The effect of invoking continuation-drop outside of the dynamic context of a with-limited-continuation is undefined.
- (continuation-suspend STORE) procedure
Captures the current continuation up to the point of the innermost enclosing with-limited-continuation form and invokes the 1-argument procedure STORE with the serialized representation (a string) of the continuation. The execution context will be exited and the enclosing with-limited-continuation form will return any results returned by STORE.
The effect of invoking continuation-suspend outside of the dynamic context of a with-limited-continuation is undefined.
Returning from STORE normally will result in undefined behaviour. Instead either terminate the current thread or process or use some form of non-local exit.
- (continuation-resume SK . RESULTS) procedure
Deserializes the continuation in the string SK and invokes it, continuing the execution suspended and stored in the serialized continuation. The given results will be returned from the continuation-suspend form that suspended SK. The effect of invoking continuation-resume outside of the dynamic context of a with-limited-continuation is undefined.
Copyright (c) 2006-2010, Felix L. Winkelmann All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the authors may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- ported to CHICKEN 4
- initial release