Statement macro
Performs an atomic test-and-set operation.
conditional-update!(local-name = place)
body
[success success-expr]
[failure failure-expr]
end
If the implementation provides the extended form of conditional-update!, place can also be a function call.
threads
threads
Performs an atomic test-and-set operation. Where appropriate, it should be implemented using dedicated processor instructions, and is expected to be extremely efficient on most platforms.
The value of the place is evaluated once to determine the initial value, which is then bound to the local-name as a lexical variable. The body is then evaluated to determine the new value for the place. The place is then conditionally updated -- which means that the following steps are performed atomically:
==, though implementations might use a more direct test for there having been an assignment to the place. It is undefined whether the test will succeed or fail in the case where the place was updated with a value that is identical to the old value when compared using \==.
If the update was successful, then conditional-update! returns the result of the success expression, or returns the new value of the place if no success clause was supplied.
If the update failed, then conditional-update! signals a condition, unless a failure clause was given, in which case the value is returned.
If the place is a name, it must be the name of a locked variable in the current module scope. See Section 4.10 on page 114.
conditional-update! may signal a condition of the following class (which is a subclass of <error>), unless a failure clause is supplied.
<conditional-update-error>
The following example does an atomic increment of *number-detected*.
until (conditional-update!
(current-val = *number-detected*)
current-val + 1
failure #f
end conditional-update!)
end until