From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kevin Ryde Newsgroups: gmane.lisp.guile.devel Subject: Re: What are the arguments in favor of delay/force in eval.c? Date: Sat, 10 Dec 2005 11:11:17 +1100 Message-ID: <873bl13j6i.fsf@zip.com.au> References: <87hd9mgc7v.fsf@trouble.defaultvalue.org> <87acfcfvbr.fsf@zip.com.au> <87y82wo78b.fsf@trouble.defaultvalue.org> <8764q0fn2f.fsf@zip.com.au> <874q5kmmup.fsf@trouble.defaultvalue.org> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1134173874 7979 80.91.229.2 (10 Dec 2005 00:17:54 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 10 Dec 2005 00:17:54 +0000 (UTC) Cc: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sat Dec 10 01:17:48 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1EksQE-0004is-AW for guile-devel@m.gmane.org; Sat, 10 Dec 2005 01:17:06 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EksQa-00022b-GM for guile-devel@m.gmane.org; Fri, 09 Dec 2005 19:17:28 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1EksLZ-0007MW-Cf for guile-devel@gnu.org; Fri, 09 Dec 2005 19:12:18 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1EksLW-0007KK-Oz for guile-devel@gnu.org; Fri, 09 Dec 2005 19:12:16 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EksLW-0007K5-5G for guile-devel@gnu.org; Fri, 09 Dec 2005 19:12:14 -0500 Original-Received: from [61.8.0.115] (helo=mailout2.pacific.net.au) by monty-python.gnu.org with esmtp (Exim 4.34) id 1EksMm-0006uN-Ui for guile-devel@gnu.org; Fri, 09 Dec 2005 19:13:33 -0500 Original-Received: from mailproxy2.pacific.net.au (mailproxy2.pacific.net.au [61.8.0.87]) by mailout2.pacific.net.au (8.13.4/8.13.4/Debian-3) with ESMTP id jBA0BcQZ027588; Sat, 10 Dec 2005 11:11:38 +1100 Original-Received: from localhost (ppp2D80.dyn.pacific.net.au [61.8.45.128]) by mailproxy2.pacific.net.au (8.13.4/8.13.4/Debian-3) with ESMTP id jBA0BWqS013197; Sat, 10 Dec 2005 11:11:33 +1100 Original-Received: from gg by localhost with local (Exim 3.36 #1 (Debian)) id 1EksKc-0000b3-00; Sat, 10 Dec 2005 11:11:18 +1100 Original-To: Rob Browning Mail-Copies-To: never User-Agent: Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:5497 Archived-At: Rob Browning writes: > > This would only work if you forbid side-effects, right? Well, leave it up to the application to keep itself out of trouble if the code is not reentrant. That'd be consistent a general policy of not stopping stupid multi-thread code, only code that might crash the interpreter. > I was also wondering about the possibilities for deadlock with the > current code, and then what they might be with a srfi-45 force, Whenever arbitrary code executes in a mutex I guess there's scope for that. srfi-45 shouldn't be inherently worse. Some code below (untested) for what I think "force" could look like without per-promise mutexes. Having a magic "uncomputed" value means no locking at all once computed (same as your code). The thunk to be called is in a separate field, zapped once no longer needed. Second block of code is with two magic "uncomputed" values, one for normal and one for srfi-45 style lazy promises. If I understand how they're supposed to work :-). #define SCM_PROMISE_DATA SCM_SMOB_OBJECT #define SCM_PROMISE_EXPR SCM_SMOB_OBJECT_2 { SCM data, expr, ans; SCM_VALIDATE_SMOB (1, promise, promise); data = SCM_PROMISE_DATA (promise); if (data != SCM_PROMISE_MAGIC_UNCOMPUTED_INDICATOR) return data; SCM_CRITICAL_SECTION_START; data = SCM_PROMISE_DATA (promise); expr = SCM_PROMISE_EXPR (promise); SCM_CRITICAL_SECTION_END; if (data != SCM_PROMISE_MAGIC_UNCOMPUTED_INDICATOR) return data; ans = scm_call_0 (expr); SCM_CRITICAL_SECTION_START; data = SCM_PROMISE_DATA (promise); if (data == SCM_PROMISE_MAGIC_UNCOMPUTED_INDICATOR) { SCM_SET_PROMISE_DATA (promise, ans); /* we set the value */ SCM_SET_PROMISE_EXPR (promise, SCM_BOOL_F); /* gc the expression */ } else { /* recursive force or other thread set the value, return that */ ans = data; } SCM_CRITICAL_SECTION_END; return ans; } { SCM data, expr, ans; SCM_VALIDATE_SMOB (1, promise, promise); again: data = SCM_PROMISE_DATA (promise); if ((data & ~1) != SCM_PROMISE_MAGIC_UNCOMPUTED) return data; SCM_CRITICAL_SECTION_START; data = SCM_PROMISE_DATA (promise); expr = SCM_PROMISE_EXPR (promise); SCM_CRITICAL_SECTION_END; if ((data & ~1) != SCM_PROMISE_MAGIC_UNCOMPUTED) return data; ans = scm_call_0 (expr); SCM_CRITICAL_SECTION_START; data = SCM_PROMISE_DATA (promise); if (data == SCM_PROMISE_MAGIC_UNCOMPUTED_LAZY && SCM_PROMISE_P (ans)) { /* SRFI-45 lazy promise, mutate ourselves to ANS and go again */ SCM_SET_PROMISE_DATA (promise, SCM_PROMISE_DATA (ans)); SCM_SET_PROMISE_EXPR (promise, SCM_PROMISE_EXPR (ans)); SCM_CRITICAL_SECTION_END; goto again; } else if (data == SCM_PROMISE_MAGIC_UNCOMPUTED_NORMAL) { SCM_SET_PROMISE_DATA (promise, ans); /* we set the value */ SCM_SET_PROMISE_EXPR (promise, SCM_BOOL_F); /* gc the expression */ } else { /* recursive force or other thread set the value, return that */ ans = data; } SCM_CRITICAL_SECTION_END; return ans; } _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://lists.gnu.org/mailman/listinfo/guile-devel