From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Rob Browning Newsgroups: gmane.lisp.guile.devel Subject: Re: What are the arguments in favor of delay/force in eval.c? Date: Wed, 07 Dec 2005 14:47:00 -0800 Message-ID: <87y82wo78b.fsf@trouble.defaultvalue.org> References: <87hd9mgc7v.fsf@trouble.defaultvalue.org> <87acfcfvbr.fsf@zip.com.au> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1133995818 10472 80.91.229.2 (7 Dec 2005 22:50:18 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 7 Dec 2005 22:50:18 +0000 (UTC) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Wed Dec 07 23:50:09 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1Ek84f-000564-WC for guile-devel@m.gmane.org; Wed, 07 Dec 2005 23:47:46 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ek84v-0001Tv-UH for guile-devel@m.gmane.org; Wed, 07 Dec 2005 17:48:01 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Ek84K-0001Mx-2E for guile-devel@gnu.org; Wed, 07 Dec 2005 17:47:24 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Ek84I-0001LE-4n for guile-devel@gnu.org; Wed, 07 Dec 2005 17:47:23 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ek84H-0001Ks-R2 for guile-devel@gnu.org; Wed, 07 Dec 2005 17:47:21 -0500 Original-Received: from [70.85.129.156] (helo=defaultvalue.org) by monty-python.gnu.org with esmtp (Exim 4.34) id 1Ek85C-0001Ae-GM for guile-devel@gnu.org; Wed, 07 Dec 2005 17:48:18 -0500 Original-Received: from omen.defaultvalue.org (localhost [127.0.0.1]) by defaultvalue.org (Postfix) with ESMTP id D2A9C90D2B for ; Wed, 7 Dec 2005 16:47:01 -0600 (CST) Original-Received: from trouble.defaultvalue.org (omen.defaultvalue.org [192.168.1.1]) by omen.defaultvalue.org (Postfix) with ESMTP id 8C57E410E for ; Wed, 7 Dec 2005 14:47:01 -0800 (PST) Original-Received: by trouble.defaultvalue.org (Postfix, from userid 1000) id ABA123C1001; Wed, 7 Dec 2005 14:47:00 -0800 (PST) Original-To: guile-devel@gnu.org In-Reply-To: <87acfcfvbr.fsf@zip.com.au> (Kevin Ryde's message of "Thu, 08 Dec 2005 08:31:20 +1100") 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:5488 Archived-At: Kevin Ryde writes: > (Speaking of which, I'd thought before that once a promise is forced > it shouldn't need a mutex any more, which would save a bit of time and > space.) I suppse it might, though you'd have to be very careful with the coding. i.e. (offhand) you would probably have to do something like this: SCM mutex = SCM_PROMISE_MUTEX(p); // assume atomic copy if(scm_is_null(mutex)) result = SCM_PROMISE_DATA(p); // [1] else { scm_lock_mutex(mutex); if(scm_is_null(SCM_PROMISE_MUTEX(p)) // must check again after lock { // someone was already evaluating when we started // (and must have finished now) result = SCM_PROMISE_DATA(p); } else { SCM ans = scm_call_0(SCM_PROMISE_DATA (ans)); SCM_SET_PROMISE_DATA(p, ans); SCM_SET_PROMISE_MUTEX(p, SCM_BOOL_F) // (do last to avoid race at [1]) result = SCM_PROMISE_DATA(p); } scm_unlock_mutex(mutex); } Note that this wouldn't be safe if the initial mutex assignment might copy a value that has been half filled by some other thread. Of course, if we're interested in srfi-45, then it would require somewhat more... -- Rob Browning rlb @defaultvalue.org and @debian.org; previously @cs.utexas.edu GPG starting 2002-11-03 = 14DD 432F AE39 534D B592 F9A0 25C8 D377 8C7E 73A4 _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://lists.gnu.org/mailman/listinfo/guile-devel