std/concurrent
std/concurrent — threads, channels, locks, atomics.
Handle-backed classes: every class carries a single handle : i64
(the registry id on the Rust side) and exposes its construction
parameters through an explicit constructor(...). Method calls
pass the handle as self to the matching__axle_stdlib_concurrent_<Class>_<m> native binding.Thread and ThreadPoolExecutor are the exception: plain Axle classes,
since without the Runnable callback ABI they hold nothing on the Rust side.
Free functions
| Type | Method and description |
|---|---|
| __nextThreadId() : i64 The id the next Thread receives: process-wide mutable state, so native. |
Method detail
#__nextThreadId
The id the next Thread receives: process-wide mutable state, so native.
C class Async
Static facade for the async (coroutine) world. Async::sleep(ms)
mints a Future<void> timer that resolves after ms milliseconds;awaiting it parks the coroutine cooperatively on the event loop
(other machines keep running) — unlike the prelude sleep(ms) ofstd/sys, which blocks the OS thread. Async::all(futures) (or await all futures)
joins a Future<T>[] into one storable Future<T[]> handle.
Methods
| Type | Method and description |
|---|---|
| sleep(self, ms : i64) : Future<void> |
Method detail
#sleep
C class Thread
An OS-level thread of execution that runs a Runnable. Named at
construction. Running one needs the Runnable callback ABI (an Axle
closure reaching a Rust trampoline), which is not wired, so start()
refuses and a Thread never runs. Every other method answers for a thread
that has not started. Use the built-in spawn fn() for real OS threads.
Constructors
| Type | Method and description |
|---|---|
| constructor(name : string) |
Method detail
#constructor
name identifier reported by getName().Methods
| Type | Method and description |
|---|---|
| start(self) : void |
| join(self) : void |
| joinWithTimeout(self, millis : i64) : void |
| getName(self) : string |
| isAlive(self) : bool |
| getId(self) : i64 |
| isDaemon(self) : bool |
| setDaemon(mut self, daemon : bool) : void |
Method detail
#start
#join
#joinWithTimeout
#getName
#isAlive
#getId
#isDaemon
#setDaemon
C class ReentrantLock
Mutual-exclusion lock that the same thread may re-acquire.
Methods take/release explicitly because Axle has no RAII guards.
Methods
| Type | Method and description |
|---|---|
| lock(self) : void |
| tryLock(self) : bool |
| unlock(self) : void |
| isLocked(self) : bool |
Method detail
#lock
#tryLock
#unlock
#isLocked
C class UnboundedChannel
Channel with no capacity bound — send never blocks on a full
queue.
Methods
| Type | Method and description |
|---|---|
| send(self, value : i32) : void |
| receive(self) : i32 |
| trySend(self, value : i32) : bool |
| tryReceive(self) : i32 |
| close(self) : void |
Method detail
#send
#receive
#trySend
#tryReceive
#close
C class BoundedChannel
Channel with a fixed capacity — send blocks once the queue is
full, giving back-pressure to the producer.
Constructors
| Type | Method and description |
|---|---|
| constructor(capacity : i32) |
Method detail
#constructor
capacity maximum number of buffered values before sendblocks the producer. A capacity below one is read
as one: a channel that buffers nothing would need
a sender and a receiver to meet inside the same
call, and this channel hands off through a queue.
Methods
| Type | Method and description |
|---|---|
| send(self, value : i32) : void |
| receive(self) : i32 |
| trySend(self, value : i32) : bool |
| tryReceive(self) : i32 |
| close(self) : void |
Method detail
#send
#receive
#trySend
#tryReceive
#close
C class ThreadPoolExecutor
Pool of worker threads sized between core and max, draining a
shared task queue. Handing a worker a Runnable needs the callback ABI,
which is not wired, so execute() refuses every task: the pool holds no
worker and its queue is always drained. Use the spawn fn() built-in
plus a channel-based work queue.
Constructors
| Type | Method and description |
|---|---|
| constructor(core : i32, max : i32) |
Method detail
#constructor
core number of always-on worker threads.max upper bound on worker threads under load.Methods
| Type | Method and description |
|---|---|
| execute(self, task : Runnable) : void |
| shutdown(self) : void |
| waitForTermination(self) : void |
| waitForTerminationWithTimeout(self, millis : i64) : bool |
Method detail
#execute
#shutdown
#waitForTermination
#waitForTerminationWithTimeout
C class AtomicI32
32-bit atomic counter with lock-free get / set / increment /
add. A reader and a writer on different threads observe a single
indivisible transition.
Constructors
| Type | Method and description |
|---|---|
| constructor(initial : i32) |
Method detail
#constructor
initial starting value of the counter.Methods
Method detail
#get
#set
#incrementAndGet
#decrementAndGet
#addAndGet
#compareAndSet
#swap
C class AtomicI64
64-bit atomic counter. Same shape as AtomicI32, including its
compare-and-swap and exchange operations; different width.
Constructors
| Type | Method and description |
|---|---|
| constructor(initial : i64) |
Method detail
#constructor
initial starting value of the counter.Methods
Method detail
#get
#set
#incrementAndGet
#decrementAndGet
#addAndGet
#compareAndSet
#swap
C class AtomicBoolean
Boolean flag with atomic load / store / CAS. Backed by anAtomicBool on the Rust side so a writer and a reader on
different threads observe a single-step transition.
Constructors
| Type | Method and description |
|---|---|
| constructor(initial : bool) |
Method detail
#constructor
initial starting value of the flag.Methods
| Type | Method and description |
|---|---|
| get(self) : bool |
| set(self, newValue : bool) : void |
| compareAndSet(self, expected : bool, update : bool) : bool |
Method detail
#get
#set
#compareAndSet
C class CountDownLatch
CountDownLatch — single-shot barrier. Construct with an
initial count, countDown() decrements, waitFor() blocks
until the count reaches zero.
Constructors
| Type | Method and description |
|---|---|
| constructor(count : i32) |
Method detail
#constructor
count number of countDown() calls before the latch opens.Methods
| Type | Method and description |
|---|---|
| countDown(self) : void |
| waitFor(self) : void |
| waitForWithTimeout(self, millis : i64) : bool |
| getCount(self) : i32 |
Method detail
#countDown
#waitFor
#waitForWithTimeout
#getCount
C class ReadWriteLock
ReadWriteLock — readers can run concurrently, the writer
holds exclusive access, and a reader arriving while a writer
waits queues behind it. Backed by the runtime's own RwLock
over the platform primitive. Methods take/release explicitly
because Axle has no RAII guards.
Methods
| Type | Method and description |
|---|---|
| readLock(self) : void |
| readUnlock(self) : void |
| writeLock(self) : void |
| writeUnlock(self) : void |
| tryReadLock(self) : bool |
| tryWriteLock(self) : bool |
Method detail
#readLock
#readUnlock
#writeLock
#writeUnlock
#tryReadLock
#tryWriteLock
C class Semaphore
Semaphore — counting permit pool. acquire() blocks when
no permit is available; release() returns one to the pool.
Constructors
| Type | Method and description |
|---|---|
| constructor(permits : i32) |
Method detail
#constructor
permits initial number of permits in the pool.Methods
| Type | Method and description |
|---|---|
| acquire(self) : void |
| tryAcquire(self) : bool |
| release(self) : void |
| availablePermits(self) : i32 |
Method detail
#acquire
#tryAcquire
#release
#availablePermits
T trait Runnable
A unit of work a Thread runs. Implemented by user code; the
runtime invokes run() once the thread is scheduled.
| Type | Method and description |
|---|---|
| run(self) : void |
Method detail
#run
T trait Condition
Wait/notify primitive paired with a lock: a thread blocks inwaitFor until another signals the condition.
| Type | Method and description |
|---|---|
| waitFor(self) : void Atomically release the lock and block until signalled, then re-acquire the lock before returning. |
| waitForMillis(self, millis : i64) : void Like waitFor, but also returns once the deadline elapses. |
| signal(self) : void Wake one thread waiting on this condition. |
| signalAll(self) : void Wake all threads waiting on this condition. |
Method detail
#waitFor
Atomically release the lock and block until signalled, then
re-acquire the lock before returning.
InterruptedException if the waiting thread is interrupted.#waitForMillis
Like waitFor, but also returns once the deadline elapses.
millis maximum time to wait, in milliseconds.InterruptedException if the waiting thread is interrupted.#signal
Wake one thread waiting on this condition.
#signalAll
Wake all threads waiting on this condition.
T trait Channel
Thread-safe message queue carrying i32 values. send / receive
block; trySend / tryReceive are the non-blocking variants.
| Type | Method and description |
|---|---|
| send(self, value : i32) : void Enqueue a value, blocking if the channel is bounded and full. |
| receive(self) : i32 Dequeue the next value, blocking until one is available. |
| trySend(self, value : i32) : bool Non-blocking enqueue. |
| tryReceive(self) : i32 Non-blocking dequeue; returns immediately whether or not a value is ready. |
| close(self) : void Close the channel; subsequent sends fail and pending receives drain. |
Method detail
#send
Enqueue a value, blocking if the channel is bounded and full.
InterruptedException if the waiting thread is interrupted.#receive
Dequeue the next value, blocking until one is available.
InterruptedException if the waiting thread is interrupted.#trySend
Non-blocking enqueue.
true if the value was accepted, false if the channelis full or closed.
#tryReceive
Non-blocking dequeue; returns immediately whether or not a value
is ready.
#close
Close the channel; subsequent sends fail and pending receives drain.
T trait Executor
Accepts Runnable work for execution on some thread-management
policy decided by the implementation.
| Type | Method and description |
|---|---|
| execute(self, task : Runnable) : void Submit a Runnable to be run under the executor's threading policy. |
Method detail
#execute
Submit a Runnable to be run under the executor's threading policy.
UnsupportedOperationException if the implementation cannotroute the Runnable callback.