Atomics

external object Atomics(source)

Functions

Link copied to clipboard
fun <T : Comparable<T>> add(typedArray: TypedArray<*, *, *, T>, index: Int, value: T): T

Adds a value to the value at the given position in the array, returning the original value. Until this atomic operation completes, any other read or write operation against the array will block.

Link copied to clipboard
fun <T : Comparable<T>> and(typedArray: TypedArray<*, *, *, T>, index: Int, value: T): T

Stores the bitwise AND of a value with the value at the given position in the array, returning the original value. Until this atomic operation completes, any other read or write operation against the array will block.

Link copied to clipboard
fun <T : Comparable<T>> compareExchange(typedArray: TypedArray<*, *, *, T>, index: Int, expectedValue: T, replacementValue: T): T

Replaces the value at the given position in the array if the original value equals the given expected value, returning the original value. Until this atomic operation completes, any other read or write operation against the array will block.

Link copied to clipboard
fun <T : Comparable<T>> exchange(typedArray: TypedArray<*, *, *, T>, index: Int, value: T): T

Replaces the value at the given position in the array, returning the original value. Until this atomic operation completes, any other read or write operation against the array will block.

Link copied to clipboard
fun isLockFree(size: Int): Boolean

Returns a value indicating whether high-performance algorithms can use atomic operations (true) or must use locks (false) for the given number of bytes-per-element of a typed array.

Link copied to clipboard
fun <T : Comparable<T>> load(typedArray: TypedArray<*, *, *, T>, index: Int): T

Returns the value at the given position in the array. Until this atomic operation completes, any other read or write operation against the array will block.

Link copied to clipboard
fun notify(typedArray: BigInt64Array<*>, index: Int, count: Int = definedExternally): Int
fun notify(typedArray: Int32Array<*>, index: Int, count: Int = definedExternally): Int

Wakes up sleeping agents that are waiting on the given index of the array, returning the number of agents that were awoken.

Link copied to clipboard
fun <T : Comparable<T>> or(typedArray: TypedArray<*, *, *, T>, index: Int, value: T): T

Stores the bitwise OR of a value with the value at the given position in the array, returning the original value. Until this atomic operation completes, any other read or write operation against the array will block.

Link copied to clipboard
fun <T : Comparable<T>> store(typedArray: TypedArray<*, *, *, T>, index: Int, value: T): T

Stores a value at the given position in the array, returning the new value. Until this atomic operation completes, any other read or write operation against the array will block.

Link copied to clipboard
fun <T : Comparable<T>> sub(typedArray: TypedArray<*, *, *, T>, index: Int, value: T): T

Subtracts a value from the value at the given position in the array, returning the original value. Until this atomic operation completes, any other read or write operation against the array will block.

Link copied to clipboard
fun wait(typedArray: BigInt64Array<*>, index: Int, value: BigInt, timeout: Int = definedExternally): WaitStatus
fun wait(typedArray: Int32Array<*>, index: Int, value: Int, timeout: Int = definedExternally): WaitStatus

If the value at the given position in the array is equal to the provided value, the current agent is put to sleep causing execution to suspend until the timeout expires (returning "timed-out") or until the agent is awoken (returning "ok"); otherwise, returns "not-equal".

Link copied to clipboard
fun waitAsync(typedArray: BigInt64Array<*>, index: Int, value: BigInt, timeout: Int = definedExternally): WaitResult
fun waitAsync(typedArray: Int32Array<*>, index: Int, value: Int, timeout: Int = definedExternally): WaitResult

A non-blocking, asynchronous version of wait which is usable on the main thread. Waits asynchronously on a shared memory location and returns a Promise

Link copied to clipboard
fun <T : Comparable<T>> xor(typedArray: TypedArray<*, *, *, T>, index: Int, value: T): T

Stores the bitwise XOR of a value with the value at the given position in the array, returning the original value. Until this atomic operation completes, any other read or write operation against the array will block.