* Support for more atomic operations
@ 2021-11-25 15:27 Olivier Dion via General Guile related discussions
0 siblings, 0 replies; only message in thread
From: Olivier Dion via General Guile related discussions @ 2021-11-25 15:27 UTC (permalink / raw)
To: guile-user
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-11-25 15:27 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-11-25 15:27 Support for more atomic operations Olivier Dion via General Guile related discussions
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).