From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Neil Jerram" Newsgroups: gmane.lisp.guile.user Subject: Re: Long-lived Guile scripts in a mono-threaded game engine Date: Tue, 27 May 2008 22:49:01 +0100 Message-ID: <49dd78620805271449u1778b5c2k56408fdabcdff9ce@mail.gmail.com> References: <20080526211900.GB14261@perso.beuc.net> <87fxs4yy89.fsf@gnu.org> <20080527083324.GA16693@perso.beuc.net> <87hccjnars.fsf@gnu.org> <20080527161445.GB18239@perso.beuc.net> <87fxs3624n.fsf@unknownlamer.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_9428_20499480.1211924941734" X-Trace: ger.gmane.org 1211942069 31170 80.91.229.12 (28 May 2008 02:34:29 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 28 May 2008 02:34:29 +0000 (UTC) Cc: guile-user@gnu.org To: "Clinton Ebadi" Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Wed May 28 04:35:01 2008 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1K1BVD-0001Bv-Qr for guile-user@m.gmane.org; Wed, 28 May 2008 04:35:00 +0200 Original-Received: from localhost ([127.0.0.1]:40043 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K1BUS-0008Oj-JS for guile-user@m.gmane.org; Tue, 27 May 2008 22:34:12 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1K172X-0005dR-Ls for guile-user@gnu.org; Tue, 27 May 2008 17:49:05 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1K172V-0005d1-Ul for guile-user@gnu.org; Tue, 27 May 2008 17:49:05 -0400 Original-Received: from [199.232.76.173] (port=53117 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K172V-0005cy-OX for guile-user@gnu.org; Tue, 27 May 2008 17:49:03 -0400 Original-Received: from wr-out-0506.google.com ([64.233.184.226]:60831) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1K172V-0008SJ-8Z for guile-user@gnu.org; Tue, 27 May 2008 17:49:03 -0400 Original-Received: by wr-out-0506.google.com with SMTP id 57so1648110wri.12 for ; Tue, 27 May 2008 14:49:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; bh=edrsMwU56EEpb+Oq0GTez72MgODaJj8y793TyfIDWfM=; b=S6YXdyTZ8+cVy7939gNNXN0KhGNtRR9stfGcsQSTAtB8LdEgvCO9jD6W2pper4rBwuABsrD8l18Qma6ks6Scla/Oz4O3oTvP0WuNhOqS77T1+U6kxQoaFDOV/InWqYEk9gNOlxUiwWrTQypf20b79MhV67r3JsGcFJoE6u46r24= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=XMAxNksH+nhrLgztV0z7CbXQdntHEOJ3D7JUw09DdRtAbbRODwpbhLw9cXmr4la4XHOs/ZqQEgoZGBop8k2dM9b6RMGo4YCxMjQjAi0JU9C8L4W/evPJo/ssHErRf9J1NUvrGw9xvTjxfKC4dL9eGYgvNz0hY9gBbh7OcSKIGQQ= Original-Received: by 10.114.130.1 with SMTP id c1mr1790792wad.156.1211924941740; Tue, 27 May 2008 14:49:01 -0700 (PDT) Original-Received: by 10.114.197.8 with HTTP; Tue, 27 May 2008 14:49:01 -0700 (PDT) In-Reply-To: <87fxs3624n.fsf@unknownlamer.org> X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 2) X-Mailman-Approved-At: Tue, 27 May 2008 22:33:15 -0400 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:6586 Archived-At: ------=_Part_9428_20499480.1211924941734 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline 2008/5/27 Clinton Ebadi : > You are pretty much doing what call/cc does, and so could > straightforwardly rewrite the functions that cause scripts to freeze > to capture the current continuation and schedule an event to resume > this continuation when needed. So something like: > > (define (say-stop message) > (call/cc (lambda (k) > (%say-stop message k)))) > > This might be worth trying and might perform well enough, but Guile's > call/cc is fairly slow and heavyweight as it must copy the entire C > stack. The amount of the stack that needs copying could be reduced, though, by putting a continuation barrier (scm_c_with_continuation_barrier) in the C code shortly before it calls out to Guile. Personally, I'd try the continuation approach. I did something just like this for a dayjob-related project, where a key objective was to make the Scheme scripts as friendly-looking as possible to non-Scheme people. I used continuations to make it possible to write a script as a sequence of apparently synchronous operations that were really asynchronous (i.e. send a request somewhere, and wait for an asynchronous response). It can be done in such a way that the call/cc is hidden down in the infrastructure, and script-writers never need to see it. A complication in my case was that the C code was sensitive to unusual return patterns. So I also needed to use a continuation to protect the C code; I can provide more detail about that if needed. Regards, Neil ------=_Part_9428_20499480.1211924941734 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline 2008/5/27 Clinton Ebadi <clinton@unknownlamer.org>:
You are pretty much doing what call/cc does, and so could
straightforwardly rewrite the functions that cause scripts to freeze
to capture the current continuation and schedule an event to resume
this continuation when needed. So something like:

(define (say-stop message)
 (call/cc (lambda (k)
            (%say-stop message k))))

This might be worth trying and might perform well enough, but Guile's
call/cc is fairly slow and heavyweight as it must copy the entire C
stack.

The amount of the stack that needs copying could be reduced, though, by putting a continuation barrier (scm_c_with_continuation_barrier) in the C code shortly before it calls out to Guile.

Personally, I'd try the continuation approach.  I did something just like this for a dayjob-related project, where a key objective was to make the Scheme scripts as friendly-looking as possible to non-Scheme people.  I used continuations to make it possible to write a script as a sequence of apparently synchronous operations that were really asynchronous (i.e. send a request somewhere, and wait for an asynchronous response).  It can be done in such a way that the call/cc is hidden down in the infrastructure, and script-writers never need to see it.

A complication in my case was that the C code was sensitive to unusual return patterns.  So I also needed to use a continuation to protect the C code; I can provide more detail about that if needed.

Regards,
        Neil

------=_Part_9428_20499480.1211924941734--