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

blocking_mutate

concur.blocking_mutate

blocking_mutate -- a variant of mutate that may be shared between threads

This mutate ensure exclusive access to shared memory via using locks and
blocking.

Accidental race accesses are not permitted by this mutate, i.e., accessing
mutable elements, e.g, via `get` or `put` on a mutable var `mutate.new T`,
are not permitted unless we are in code run via
`blocking_mutate.this.exclusive`.

Constructors

(T 
type
)
:
Mutable_Array T, mutate.this,mutable_element
 is
[Inherited from  mutate]
[Private constructor]
create a mutable array.
(T 
type
)
:
Mutable_Array2 T, mutate.this,mutable_element
 is
[Inherited from  mutate]
[Private constructor]
create a mutable array with two dimensions.
(T 
type
)
:
Mutable_Array3 T, mutate.this,mutable_element
 is
[Inherited from  mutate]
[Private constructor]
create a mutable array with three dimensions.
(T 
type
)
 ref
:
Circular_Buffer T, mutate.this,mutable_element
 is
[Inherited from  mutate]
[Private constructor]
create a circular buffer.

buffer to which elements can be enqueued and retrieved with a FIFO
logic.

backed by a fixed length array.
:
Any
 is
[Inherited from  mutate]
[Private constructor]
common type for mutable data
(T 
type
, mutable_value T)
:
mutable_element,auto_unwrap T, mutate
 is
[Inherited from  mutate]
create a new mutable value with the given initial value and update the
'mutate' effect in the current environment

Functions

 => 
bool
[Inherited from  mutate]
does this effect support abort?

redefines:

(R 
type
, E 
type
:
effect, e Lazy E)
 => 
Functional R
[Inherited from  effect]
fluent interface for using multiple effects together
(R 
type
)
 => 
Functional R
[Inherited from  effect]
this effect reinterpreted as a Functional
which allows composition of effects
 => 
String
[Inherited from  Any]
create a String from this instance. Unless redefined, `a.as_string` will
create `"instance[T]"` where `T` is the dynamic type of `a`
(R 
type
, F 
type
: Typed_Function R, f F)
 => 
R
[Inherited from  Any]
dynamic_apply -- apply `f.call` to `Any.this`'s dynamic type and value

This can be used to perform operation on values depending on their dynamic
type.

Here is an example that takes a `Sequence Any` that may contain boxed values
of types `i32` and `f64`. We can now write a feature `get_f64` that extracts
these values converted to `f64` and build a function `sum` that sums them up
as follows:


 => 
Type
[Inherited from  Any]
Get the dynamic type of this instance. For value instances `x`, this is
equal to `type_of x`, but for `x` with a `ref` type `x.dynamic_type` gives
the actual runtime type, while `type_of x` results in the static
compile-time type.

There is no dynamic type of a type instance since this would result in an
endless hierarchy of types. So for Type values, dynamic_type is redefined
to just return Type.type.
(R 
type
, F 
type
: Function R, code F)
 => 
R
[Redefinition of  mutate.exclusive]
perform given code with exclusive access to the mutable values created with
this instance of `mutate`.

redefines:

(R 
type
, C 
type
:
Function, F 
type
: Function R, condition C, code F)
 => 
R
[Inherited from  mutate]
exclusively wait for the given condition to hold and then perform given code with
exclusive access to the mutable values created with this instance of `mutate`.
 => 
unit
[Redefinition of  effect.finally]
cleanup feature to destroy mutex and other resources associated with this
effect.

NYI: UNDER DEVELOPMENT: Ensure that this does not get redefined by user
code.

redefines:

(R 
type
, code Function R)
 => 
R
[Inherited from  effect]
infix variant instate_self

use it like this:

(R 
type
, code Function R)
 => 
R
[Inherited from  effect]
convenience version of `instate` for effect values whose type is
exactly the effect type (i.e., the value type does not inherit
from the effect type).

Execute 'code' in a context where this effect instance has been
instated for effect type `effect.this`.

In case `f` returns normally, this will return `f`'s result.

In case `f` aborts this effect, this will panic.
 => 
bool
[Inherited from  mutate]
check if the current thread is permitted to access mutable state managed by mutate.this
exclusively.

For a single-thread mutate, this is usually the case for the same thread this mutate was
created in. Furthermore, multi-thread mutate implementations may ensure exclusive
access to other threads via redefining the `exclusive` features.
is instance `mutate.this` instated for type `mutate.this` and, if `mutate.this` does
not support use in several threads, check we are running in the thread `mutate.this`
was created in?
(T 
type
, length i64, init T)
 => 
mutate.this.array T
[Inherited from  mutate]
convenience feature for creating a new array,
in some cases even with type inference
(T 
type
, length0 i64, length1 i64, init T)
 => 
container.Mutable_Array2 T mutate.this
[Inherited from  mutate]
convenience feature for creating a new array2,
in some cases even with type inference
(T 
type
, length0 i64, length1 i64, length2 i64, init T)
 => 
container.Mutable_Array3 T mutate.this
[Inherited from  mutate]
convenience feature for creating a new array3,
in some cases even with type inference
 => 
String
[Inherited from  Any]
convenience prefix operator to create a string from a value.

This permits usage of `$` as a prefix operator in a similar way both
inside and outside of constant strings: $x and "$x" will produce the
same string.
 => 
unit
[Inherited from  effect]
replace existing effect of type `effect.this` by the new effect value `effect.this`.

This is a convenience feature for value type effects for which the type of
the effect instance equals the effect type. `ref` type effects typically have
values that may be children of the effect type that are of a different type, so
`effect_type.replace new_value` must be used.

replace may only be called during the execution of an operation of a currently instated
effect of the same effect type.
(F 
type
:
Function, condition F)
 => 
unit
[Redefinition of  mutate.wait]
wait for the given condition to become true by a mutation of the underlying data.

In case this mutate is not a multi-thread implementation and `condition()` is `false`,
this will `panic`.

redefines:

Type Functions

 => 
void
[Inherited from  effect]
Abort code execution for the instated effect.this.env and return to the point
where the effect was instated.
(e effect.this.type)
 => 
void
[Inherited from  effect]
replace existing effect for type `effect.this` by the new effect value `e`
and abort code execution to return to the point where the effect was instated.
 => 
String
[Inherited from  Type]
string representation of this type to be used for debugging.

result has the form "Type of '<name>'", but this might change in the future

redefines:

If this effect may be instated automatically at application start (during the
effect big bang singularity), this should be redefined to return the
corresponding effect value
 => 
Type
[Inherited from  Type]
There is no dynamic type of a type instance since this would result in an
endless hierarchy of types, so dynamic_type is redefined to just return
Type.type here.

redefines:

 => 
effect.this.type
[Inherited from  effect]
get this effect from env
has an effect of the given type been instated?
(T 
type
)
 => 
bool
[Inherited from  Type]
Is this type assignable to a type parameter with constraint `T`?

The result of this is a compile-time constant that can be used to specialize
code for a particular type.


it is most useful in conjunction with preconditions or `if` statements as in


or

(E 
type
:
effect, e E)
 => 
effect_to_be_instated E
[Inherited from  effect]
infix variant of effect.instate

use it like this:

(R 
type
, e effect.this.type, code Function R)
 => 
R
[Inherited from  effect]
execute 'code' in a context where the effect instance `e` has been
installed for effect type `effect.this`.

In case `f` returns normally, this will return `f`'s result.

In case `f` aborts this effect, this will panic.
(R 
type
, e effect.this.type, code Function R, def Unary R effect.this.type)
 => 
R
[Inherited from  effect]
execute 'code' in a context where the effect instance `e` has been
installed for effect type `effect.this`.

In case `f` returns normally, this will return `f`'s result.

In case `f` aborts this effect, return `def()`.
 => 
bool
[Inherited from  effect]
has an effect of this type been instated?
 => 
String
[Inherited from  Type]
name of this type, including type parameters, e.g. 'option (list i32)'.
 => 
String
[Inherited from  Type]
convenience prefix operator to create a string from a value.

This permits usage of `$` as a prefix operator in a similar way both
inside and outside of constant strings: $x and "$x" will produce the
same string.

NYI: Redefinition allows the type feature to be distinguished from its normal counterpart, see #3913

redefines:

(e effect.this.type)
 => 
unit
[Inherited from  effect]
replace existing effect for type `effect.this` by the new effect value `e`.

For effects that model the outside world (e.g., i/o, time, sensors and actuators, etc.),
the effect might be a unit type, so the replace is effectively a no-operation. However,
the call to `replace` is used ot model the change of the outside world and must be
included for analysis tools to appreciate this.

replace may only be called during the execution of an operation of a currently instated
effect of the same effect type.

NYI: BUG: It is currently not enforced that replace is only called during the execution
of an operation of a currently instated effect of the same effect type.
 => 
Type
[Inherited from  Any]
Get a type as a value.

This is a feature with the effect equivalent to Fuzion's `expr.type` call tail.
It is recommended to use `expr.type` and not `expr.type_value`.

`type_value` is here to show how this can be implemented and to illustrate the
difference to `dynamic_type`.
0.095dev (GIT hash fe578dbae82d257bfb6d755e3b05abbf37247dbe)
last changed: 2026-05-12