Skip to content

Latest commit

 

History

History
44 lines (35 loc) · 1.18 KB

0058-atomics.org

File metadata and controls

44 lines (35 loc) · 1.18 KB

atomics

This is a portability library for access to atomic operation primitives such as compare-and-swap, atomic-incf and atomic-decf.

Atomic operations are particularly useful for implementing lockless algorithms.

Here is an example of using compare and swap under SBCL:

POFTHEDAY> (let ((foo (list 1 2 3 4)))
             (atomics:cas (car foo)
                          1
                          42)
             foo)

-> (LET ((FOO (LIST 1 2 3 4)))
     (LET ((#:OLD0 1))
       (EQ #:OLD0
           (LET ((#:CONS1 FOO))
             (LET ((#:OLD2 #:OLD0))
               (LET ((#:NEW3 42))
                 (SB-KERNEL:%COMPARE-AND-SWAP-CAR #:CONS1
                                                  #:OLD2
                                                  #:NEW3))))))
     FOO)

(42 2 3 4)

“atomics”, like all @shinmera’s libraries, has a good documentation where you can find details on support for atomics operations in different CL implementations.