From: Olivier Dion via General Guile related discussions <guile-user@gnu.org>
To: guile-user@gnu.org
Subject: Support for more atomic operations
Date: Thu, 25 Nov 2021 10:27:40 -0500 [thread overview]
Message-ID: <87fsrk9rwz.fsf@laura> (raw)
Hi!
Does anyone know if Guile plans to have better support for atomic
operations? For example `atomic-box-fetch-and-add!`.
I know that in theory, one can do the following:
------------------------------------------------------------------------------
(define (atomic-box-fetch-and-apply! box op value)
(let ([old (atomic-box-ref box)])
(if (eq? old
(atomic-box-compare-and-swap! box old (op old value)))
old
(atomic-box-fetch-and-apply! box op value))))
(define (atomic-box-fetch-and-add! box value)
(atomic-box-fetch-and-apply! box + value))
(define (atomic-box-fetch-and-sub! box value)
(atomic-box-fetch-and-apply! box - value))
(define (atomic-box-fetch-and-xor! box value)
(atomic-box-fetch-and-apply! box logxor value))
...
------------------------------------------------------------------------------
and it works.
But I think such operations would be faster if available as primitives in
the VM, if that's possible?
--
Olivier Dion
Polymtl
reply other threads:[~2021-11-25 15:27 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=87fsrk9rwz.fsf@laura \
--to=guile-user@gnu.org \
--cc=olivier.dion@polymtl.ca \
/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).