guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Support for more atomic operations


From: Olivier Dion
Subject: Support for more atomic operations
Date: Thu, 25 Nov 2021 10:27:40 -0500

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 via email to

[Prev in Thread] Current Thread [Next in Thread]