Stdlib index
- Captured-borrow migration worklist (3.3.3)
- Owned-bind migration worklist (8.2.7)
- Return-side title audit — the ride-through enumeration
- stdlib ownership audit
- stdlib ownership dispositions (plan 1.3.1 / 4.3.1)
aot
codec
codec / csv
codec / json
collection
- ArrayList
- BPlusTree
- Cache
- Collectors
- HashMap
- HashSet
- Heap
- ImmutableList
- ImmutableMap
- ImmutableSet
- LinkedList
- RedBlackTree
- Sort
collection / ltm
concurrent
error
- Exception
- NoOptionalValueException
- NotProvidedException
- RecoverableException
- ScopedBuildFailedException
- ScopeNotActiveException
- Throwable
- UnrecoverableException
gfx
hash
ifx
io
io / file
io / net
io / net / dns
io / net / uri
lang
lang / stream
math
math / fft
math / linalg
math / npio
math / poly
math / random
math / stats
nucleo
- Columns — the Arrow-laid-out substrate
- Fused tensor expressions — Fuse
- Table — the lazy, typed dataframe
- Tape — define-by-run autograd
- Transform intrinsics — Grad, Vmap, Jit
process
reflect
search / distance
search / fuzzy
search / ngram
session
time
- Clock
- DateTimeFormatter
- Duration
- Instant
- LocalDate
- LocalDateTime
- LocalTime
- Period
- ZonedDateTime
- ZoneId
- ZoneOffset
wire
xpu
xpu / mesh
Mutex<T>
cajeta.concurrent.Mutex — fused mutual-exclusion + protected data. The mutex
owns a single piece of data T, and the only way to touch it is to hold the
lock: access goes through withLock, whose closure is the critical section —
the current value is handed in, the closure’s result is stored back, and the
lock is released on return or unwind. “Read/write the data without the lock”
is structurally unrepresentable. Acquiring a held lock from a fiber parks the
fiber and yields to its carrier rather than blocking the OS thread.
Mutex<int32> counter = heap Mutex<int32>(0);
counter.withLock((int32 v) -> v + 1); // increment inside the critical section
counter.withLock((int32 v) -> v + 1);
int32 now = counter.get(); // snapshot under the lock -> 2
Methods
| Signature | |
|---|---|
Mutex(#T initial) ⚑ | Wrap initial in a fresh mutex, taking ownership of the value |
void withLock((T) -> #T fn) | Run fn as the critical section: acquire, pass the current value, store fn’s result, release; exception-safe, wakes withLockWhen waiters |
void withLockWhen((T) -> boolean cond, (T) -> #T fn) | Wait-for-condition critical section: block until cond(value) holds, then run fn and store its result; cond must be side-effect-free |
T get() | Snapshot the protected value under the lock; intended for value/primitive T |
⚑ = @EntryPoint
See also
- Tour: ConcurrentDemo
- Source:
runtime/src/cajeta/concurrent/Mutex.cajeta - Lock — the no-data gate; RwLock — read-heavy sibling; AtomicInt32