The Atomics object provides atomic operations as static methods. They are used with SharedArrayBuffer and ArrayBuffer objects.

Documentation Atomics by Mozilla Contributors, licensed under CC-BY-SA 2.5.

Static methods

staticadd(typedArray:IntTypedArray, index:Int, value:Int):Int

Adds the provided value to the existing value at the specified index of the array. Returns the old value at that index. This atomic operation guarantees that no other write happens until the modified value is written back.

staticand(typedArray:IntTypedArray, index:Int, value:Int):Int

Computes a bitwise AND on the value at the specified index of the array with the provided value. Returns the old value at that index. This atomic operation guarantees that no other write happens until the modified value is written back.

staticcompareExchange(typedArray:IntTypedArray, index:Int, expectedValue:Int, replacementValue:Int):Int

Stores a value at the specified index of the array, if it equals a value. Returns the old value. This atomic operation guarantees that no other write happens until the modified value is written back.

staticexchange(typedArray:IntTypedArray, index:Int, value:Int):Int

Stores a value at the specified index of the array. Returns the old value. This atomic operation guarantees that no other write happens until the modified value is written back.

staticisLockFree(size:Int):Bool

An optimization primitive that can be used to determine whether to use locks or atomic operations. Returns true if an atomic operation on arrays of the given element size will be implemented using a hardware atomic operation (as opposed to a lock). Experts only.

staticload(typedArray:IntTypedArray, index:Int):Int

Returns the value at the specified index of the array. This atomic operation guarantees that no other write happens until the modified value is written back.

staticnotify(typedArray:IntTypedArray, index:Int, ?count:Int):Int

Notifies agents that are waiting on the specified index of the array. Returns the number of agents that were notified.

staticor(typedArray:IntTypedArray, index:Int, value:Int):Int

Computes a bitwise OR on the value at the specified index of the array with the provided value. Returns the old value at that index. This atomic operation guarantees that no other write happens until the modified value is written back.

staticstore(typedArray:IntTypedArray, index:Int, value:Int):Int

Stores a value at the specified index of the array. Returns the value. This atomic operation guarantees that no other write happens until the modified value is written back.

staticsub(typedArray:IntTypedArray, index:Int, value:Int):Int

Subtracts a value at the specified index of the array. Returns the old value at that index. This atomic operation guarantees that no other write happens until the modified value is written back.

staticwait(typedArray:Int32Array, index:Int, value:Int, ?timeout:Int):WaitValue

Verifies that the specified index of the array still contains a value and sleeps awaiting or times out. Returns either "ok", "not-equal", or "timed-out". If waiting is not allowed in the calling agent then it throws an Error exception. Most browsers will not allow wait() on the browser's main thread.)

staticxor(typedArray:IntTypedArray, index:Int, value:Int):Int

Computes a bitwise XOR on the value at the specified index of the array with the provided value. Returns the old value at that index. This atomic operation guarantees that no other write happens until the modified value is written back.