Axle v0.14.1
Package

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

TypeMethod and description
i64
__nextThreadId() : i64 The id the next Thread receives: process-wide mutable state, so native.

Method detail

#__nextThreadId

__nextThreadId() : i64

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) of
std/sys, which blocks the OS thread. Async::all(futures) (or await all futures)
joins a Future<T>[] into one storable Future<T[]> handle.

Methods

TypeMethod and description
Future<void>
sleep(self, ms : i64) : Future<void>

Method detail

#sleep

sleep(self, ms : i64) : Future<void>

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

TypeMethod and description
constructor(name : string)

Method detail

#constructor

constructor(name : string)

Parameters
name identifier reported by getName().

Methods

Method detail

#start

start(self) : void ! UnsupportedOperationException

#join

join(self) : void ! InterruptedException

#joinWithTimeout

joinWithTimeout(self, millis : i64) : void ! InterruptedException

#getName

getName(self) : string

#isAlive

isAlive(self) : bool

#getId

getId(self) : i64

#isDaemon

isDaemon(self) : bool

#setDaemon

setDaemon(mut self, daemon : bool) : void

C class ReentrantLock

Mutual-exclusion lock that the same thread may re-acquire.
Methods take/release explicitly because Axle has no RAII guards.

Methods

Method detail

#lock

lock(self) : void

#tryLock

tryLock(self) : bool

#unlock

unlock(self) : void

#isLocked

isLocked(self) : bool

C class UnboundedChannel

Channel with no capacity bound — send never blocks on a full
queue.

Methods

Method detail

#send

send(self, value : i32) : void ! InterruptedException

#receive

receive(self) : i32 ! InterruptedException

#trySend

trySend(self, value : i32) : bool

#tryReceive

tryReceive(self) : i32

#close

close(self) : void ! IOException

C class BoundedChannel

Channel with a fixed capacity — send blocks once the queue is
full, giving back-pressure to the producer.

Constructors

TypeMethod and description
constructor(capacity : i32)

Method detail

#constructor

constructor(capacity : i32)

Parameters
capacity maximum number of buffered values before send
blocks 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

Method detail

#send

send(self, value : i32) : void ! InterruptedException

#receive

receive(self) : i32 ! InterruptedException

#trySend

trySend(self, value : i32) : bool

#tryReceive

tryReceive(self) : i32

#close

close(self) : void ! IOException

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

TypeMethod and description
constructor(core : i32, max : i32)

Method detail

#constructor

constructor(core : i32, max : i32)

Parameters
core number of always-on worker threads.
max upper bound on worker threads under load.

Methods

Method detail

#execute

execute(self, task : Runnable) : void ! UnsupportedOperationException

#shutdown

shutdown(self) : void

#waitForTermination

waitForTermination(self) : void ! InterruptedException

#waitForTerminationWithTimeout

waitForTerminationWithTimeout(self, millis : i64) : bool ! InterruptedException

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

TypeMethod and description
constructor(initial : i32)

Method detail

#constructor

constructor(initial : i32)

Parameters
initial starting value of the counter.

Methods

Method detail

#get

get(self) : i32

#set

set(self, newValue : i32) : void

#incrementAndGet

incrementAndGet(self) : i32

#decrementAndGet

decrementAndGet(self) : i32

#addAndGet

addAndGet(self, delta : i32) : i32

#compareAndSet

compareAndSet(self, expected : i32, update : i32) : bool

#swap

swap(self, newValue : i32) : i32

C class AtomicI64

64-bit atomic counter. Same shape as AtomicI32, including its
compare-and-swap and exchange operations; different width.

Constructors

TypeMethod and description
constructor(initial : i64)

Method detail

#constructor

constructor(initial : i64)

Parameters
initial starting value of the counter.

Methods

Method detail

#get

get(self) : i64

#set

set(self, newValue : i64) : void

#incrementAndGet

incrementAndGet(self) : i64

#decrementAndGet

decrementAndGet(self) : i64

#addAndGet

addAndGet(self, delta : i64) : i64

#compareAndSet

compareAndSet(self, expected : i64, update : i64) : bool

#swap

swap(self, newValue : i64) : i64

C class AtomicBoolean

Boolean flag with atomic load / store / CAS. Backed by an
AtomicBool on the Rust side so a writer and a reader on
different threads observe a single-step transition.

Constructors

TypeMethod and description
constructor(initial : bool)

Method detail

#constructor

constructor(initial : bool)

Parameters
initial starting value of the flag.

Methods

Method detail

#get

get(self) : bool

#set

set(self, newValue : bool) : void

#compareAndSet

compareAndSet(self, expected : bool, update : bool) : bool

C class CountDownLatch

CountDownLatch — single-shot barrier. Construct with an
initial count, countDown() decrements, waitFor() blocks
until the count reaches zero.

Constructors

TypeMethod and description
constructor(count : i32)

Method detail

#constructor

constructor(count : i32)

Parameters
count number of countDown() calls before the latch opens.

Methods

Method detail

#countDown

countDown(self) : void

#waitFor

waitFor(self) : void ! InterruptedException

#waitForWithTimeout

waitForWithTimeout(self, millis : i64) : bool ! InterruptedException

#getCount

getCount(self) : i32

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

Method detail

#readLock

readLock(self) : void

#readUnlock

readUnlock(self) : void

#writeLock

writeLock(self) : void

#writeUnlock

writeUnlock(self) : void

#tryReadLock

tryReadLock(self) : bool

#tryWriteLock

tryWriteLock(self) : bool

C class Semaphore

Semaphore — counting permit pool. acquire() blocks when
no permit is available; release() returns one to the pool.

Constructors

TypeMethod and description
constructor(permits : i32)

Method detail

#constructor

constructor(permits : i32)

Parameters
permits initial number of permits in the pool.

Methods

Method detail

#acquire

acquire(self) : void ! InterruptedException

#tryAcquire

tryAcquire(self) : bool

#release

release(self) : void

#availablePermits

availablePermits(self) : i32

T trait Runnable

A unit of work a Thread runs. Implemented by user code; the
runtime invokes run() once the thread is scheduled.

TypeMethod and description
void
run(self) : void

Method detail

#run

run(self) : void

T trait Condition

Wait/notify primitive paired with a lock: a thread blocks in
waitFor until another signals the condition.

TypeMethod and description
void
waitFor(self) : void Atomically release the lock and block until signalled, then
re-acquire the lock before returning.
void
waitForMillis(self, millis : i64) : void Like waitFor, but also returns once the deadline elapses.
void
signal(self) : void Wake one thread waiting on this condition.
void
signalAll(self) : void Wake all threads waiting on this condition.

Method detail

#waitFor

waitFor(self) : void ! InterruptedException

Atomically release the lock and block until signalled, then
re-acquire the lock before returning.

Throws
InterruptedException if the waiting thread is interrupted.

#waitForMillis

waitForMillis(self, millis : i64) : void ! InterruptedException

Like waitFor, but also returns once the deadline elapses.

Parameters
millis maximum time to wait, in milliseconds.
Throws
InterruptedException if the waiting thread is interrupted.

#signal

signal(self) : void

Wake one thread waiting on this condition.

#signalAll

signalAll(self) : void

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.

TypeMethod and description
void
send(self, value : i32) : void Enqueue a value, blocking if the channel is bounded and full.
i32
receive(self) : i32 Dequeue the next value, blocking until one is available.
bool
trySend(self, value : i32) : bool Non-blocking enqueue.
i32
tryReceive(self) : i32 Non-blocking dequeue; returns immediately whether or not a value
is ready.
void
close(self) : void Close the channel; subsequent sends fail and pending receives drain.

Method detail

#send

send(self, value : i32) : void ! InterruptedException

Enqueue a value, blocking if the channel is bounded and full.

Throws
InterruptedException if the waiting thread is interrupted.

#receive

receive(self) : i32 ! InterruptedException

Dequeue the next value, blocking until one is available.

Throws
InterruptedException if the waiting thread is interrupted.

#trySend

trySend(self, value : i32) : bool

Non-blocking enqueue.

Returns true if the value was accepted, false if the channel
is full or closed.

#tryReceive

tryReceive(self) : i32

Non-blocking dequeue; returns immediately whether or not a value
is ready.

#close

close(self) : void ! IOException

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.

TypeMethod and description
void
execute(self, task : Runnable) : void Submit a Runnable to be run under the executor's threading policy.

Method detail

#execute

execute(self, task : Runnable) : void ! UnsupportedOperationException

Submit a Runnable to be run under the executor's threading policy.

Throws
UnsupportedOperationException if the implementation cannot
route the Runnable callback.