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
Semaphore
cajeta.concurrent.Semaphore — counting permit pool that bounds the number of
concurrent operations against an unbounded set of consumers. Built on the lock
- condition-variable intrinsics:
acquirewaits for a free permit then takes one,releasereturns one and wakes a waiter. If a workload is statically batchable into “K at a time”, a chunkedscope { spawn K times }expresses the limit in the program’s shape; reach forSemaphorewhen consumers are unbounded and no scope can serve as the batching boundary.
Semaphore gate = heap Semaphore(2);
gate.acquire();
int32 avail = gate.availablePermits(); // 1
gate.release();
Methods
| Signature | |
|---|---|
Semaphore(int32 initial) ⚑ | Create a semaphore seeded with initial free permits — the cap on concurrent holders |
void acquire() | Take one permit, blocking (parking the fiber) until one is free |
void release() | Return one permit, waking a waiter so it can re-check |
void withPermit(() -> void fn) | Run fn while holding a permit, releasing it even if fn throws |
int32 availablePermits() | Current free-permit count (snapshot; advisory under contention) |
⚑ = @EntryPoint
See also
- Tour: ConcurrentDemo
- Source:
runtime/src/cajeta/concurrent/Semaphore.cajeta - Lock, Mutex