Next: Mutex Support, Previous: Special Variables, Up: Threading
SBCL provides a few special purpose atomic operations, particularly useful for implementing lockless algorithms.
Atomically decrements
placebydiff, and returns the value ofplacebefore the increment.The decrementation is done using word-size modular arithmetic: on 32 bit platforms
atomic-decfof #x0 by one results in #xFFFFFFFF being stored inplace.
placemust be an accessor form whosecaris the name of adefstructaccessor whose declared type is (UNSIGNED-BYTE 32) on 32 bit platforms, and (UNSIGNED-BYTE 64) on 64 bit platforms.
diffdefaults to 1, and must be a (SIGNED-BYTE 32) on 32 bit platforms, and (SIGNED-BYTE 64) on 64 bit platforms.
experimental:Interface subject to change.
Atomically increments
placebydiff, and returns the value ofplacebefore the increment.The incrementation is done using word-size modular arithmetic: on 32 bit platforms
atomic-incfof #xFFFFFFFF by one results in #x0 being stored inplace.
placemust be an accessor form whosecaris the name of adefstructaccessor whose declared type is (UNSIGNED-BYTE 32) on 32 bit platforms, and (UNSIGNED-BYTE 64) on 64 bit platforms.
diffdefaults to 1, and must be a (SIGNED-BYTE 32) on 32 bit platforms, and (SIGNED-BYTE 64) on 64 bit platforms.
experimental:Interface subject to change.
Atomically stores
newinplaceifoldmatches the current value ofplace. Two values are considered to match if they areeq. Returns the previous value ofplace:if the returned value iseqtoold, the swap was carried out.
placemust be an accessor form whosecaris one of the following:
car,cdr,first,rest,symbol-plist,symbol-value,svrefor the name of a
defstructcreated accessor for a slot whose declared type is eitherfixnumort. Results are unspecified if the slot has a declared type other thenfixnumort.
experimental:Interface subject to change.