Qu

mutex_get

Builtin index · Concurrency

result = mutex_get(m)

Input: m · Output: result

What it is

Reads the current value out of mutex handle m. Locked only for the instant it takes to clone the value out.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = mutex_get(m)
m —not documented yet
result —
Returns whatever value is currently stored (same type as the last mutex_set/mutex/mutex_add/mutex_update put there).

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

counter = mutex(0)
parallel for i in 1 to 100
    mutex_add(counter, 1)
end parallel
print("total {mutex_get(counter)}")
output
total 100

from specialized

counter = mutex(0)
parallel for i in 1 to 100
    mutex_add(counter, 1)              # atomic; 100 in, 100 out, no lost updates

end parallel
total = mutex_get(counter)
print(total)                           # 100

output
100

from concurrency

running_max(current) := max(current, 7)

m = mutex(0)
mutex_set(m, 3)                        # overwrite -- no read involved

mutex_update(m, "running_max")         # atomic read-modify-write via a user fn

print(mutex_get(m))                    # 7

output
7

from concurrency

How it works

mutex_get(m) — read the current value. Locked only for the instant it takes to clone the value out.

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.