From: Rob Browning <rlb@defaultvalue.org>
Subject: Re: What are the arguments in favor of delay/force in eval.c?
Date: Wed, 07 Dec 2005 14:47:00 -0800 [thread overview]
Message-ID: <87y82wo78b.fsf@trouble.defaultvalue.org> (raw)
In-Reply-To: <87acfcfvbr.fsf@zip.com.au> (Kevin Ryde's message of "Thu, 08 Dec 2005 08:31:20 +1100")
Kevin Ryde <user42@zip.com.au> 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
next prev parent reply other threads:[~2005-12-07 22:47 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-12-06 21:14 What are the arguments in favor of delay/force in eval.c? Rob Browning
2005-12-07 21:31 ` Kevin Ryde
2005-12-07 22:47 ` Rob Browning [this message]
2005-12-08 0:29 ` Kevin Ryde
2005-12-08 0:52 ` Rob Browning
2005-12-10 0:11 ` Kevin Ryde
2005-12-10 4:23 ` Rob Browning
2005-12-14 21:10 ` Kevin Ryde
2005-12-08 0:57 ` Ken Raeburn
2005-12-08 1:28 ` Rob Browning
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87y82wo78b.fsf@trouble.defaultvalue.org \
--to=rlb@defaultvalue.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).