Fuzion Logo
fuzion-lang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.

compare_and_set

mutate.var.compare_and_set

(expected T, modified T)
 => 
bool
compare the value of this mutable field with an `expected` value. If it is bitwise
equal, replace the value by with the `modified` value.

If the value was replaced, return true, otherwise return false,

Note that bitwise equality may differ from equality defined by
`property.equatable.type.equality`. In particular, e.g., for `f64`, we have
`0.0 = -0.0` while both values differ when compared bit by bit.

For a reference type `T`, this operation will compare the internal representation
of the reference value, not the referenced value. In particular, this means that
references that are typically equal like `id String "Hello!"` and
`id String "Hello" + "!"` may be represented by distinct `String` reference
values.

Check that the mutate effect this was created with is still
instated in the current environment.

Different kinds of mutate will make different efforts for synchronization:

- for a thread-local `mutate`, this can be used only by the thread that instated
the `mutate`, no synchronization will be performed.

- for a `concur.blocking_mutate`/`concur.blocking_mutate_using_clock`, this will
use `exclusive` to ensure atomicity

- for a `atomic_mutate`, this will use an atomic compare-and-set operation.
Precondition
pre
  safety: open
0.099dev (GIT hash 1bef408f37c37f3ff3417cdf772c6c40c76064ca)
last changed: 2026-09-17