Description
The macro
define-atomic-modify-macro
has the same syntax as
cl:define-modify-macro
, and performs a similar operation.
The resulting macro
name
can be used only on one of the specific set of places defined for low level atomic operations as listed in Low level atomic operations. The macro
name
reads the value of the
place
, calls the function
function
, and then writes the result of the function call if the value in
place
has not changed since it was first read. If that value did change, the operation is repeated until it succeeds.
Note that this means:
-
The function
function
may be called more than once for each invocation of the defined macro. Therefore
function
should not have any side effects.
-
function
must be thread-safe, because it may run concurrently in several threads if the defined macro
name
is used from several threads simultaneously.
-
It is possible in principle for the value to change more than once between reading the
place
and writing the new value. This may end up resetting the value in
place
to its original value, and hence the operation will succeed. This is equivalent to the code being invoked after the last change, unless
function
itself looks at
place
, which may cause inconsistent results.