Systems
vthreading
Locks and atomic counters, built on spawn, await, share and protect.
Released v1.0.0 · 2026-09-28use "stdlib/threading.ven"
l = lock_new()
print lock_run(l, make() give 41 + 1)
:: 42
Reference (7 functions)
API reference
lock_run(l, work_fn)
Runs work_fn with l held, giving back its result.
l = lock_new()
lock_run(l, make() give 41 + 1)
:: 42atomic_counter_new()
Builds a new atomic counter handle, starting at zero.
c = atomic_counter_new()
atomic_counter_increment(c)
atomic_counter_add(c, 5)
atomic_counter_value(c)
:: 6atomic_counter_increment(counter)
Increments counter by one, under its own protection.
c = atomic_counter_new()
atomic_counter_increment(c)
atomic_counter_value(c)
:: 1atomic_counter_add(counter, amount)
Adds amount to counter, under its own protection.
c = atomic_counter_new()
atomic_counter_add(c, 5)
atomic_counter_value(c)
:: 5atomic_counter_value(counter)
Gives back counters current value, under its own protection.
c = atomic_counter_new()
atomic_counter_increment(c)
atomic_counter_add(c, 5)
atomic_counter_value(c)
:: 6run_concurrently(work_fns)
Runs every function in work_fns concurrently, giving back their results in order.
run_concurrently([make() give 1 + 1, make() give 2 + 2, make() give 3 + 3])
:: [2, 4, 6]