Expand description
The Atomics
object provides atomic operations as static methods.
They are used with SharedArrayBuffer
objects.
The Atomic operations are installed on an Atomics
module. Unlike
the other global objects, Atomics
is not a constructor. You cannot
use it with a new operator or invoke the Atomics
object as a
function. All properties and methods of Atomics
are static
(as is the case with the Math object, for example).
MDN documentation
Functions§
- add
- The static
Atomics.add()
method adds a given value at a given position in the array and returns the old value at that position. This atomic operation guarantees that no other write happens until the modified value is written back. - add_
bigint - The static
Atomics.add()
method adds a given value at a given position in the array and returns the old value at that position. This atomic operation guarantees that no other write happens until the modified value is written back. - and
- The static
Atomics.and()
method computes a bitwise AND with a given value at a given position in the array, and returns the old value at that position. This atomic operation guarantees that no other write happens until the modified value is written back. - and_
bigint - The static
Atomics.and()
method computes a bitwise AND with a given value at a given position in the array, and returns the old value at that position. This atomic operation guarantees that no other write happens until the modified value is written back. - compare_
exchange - The static
Atomics.compareExchange()
method exchanges a given replacement value at a given position in the array, if a given expected value equals the old value. It returns the old value at that position whether it was equal to the expected value or not. This atomic operation guarantees that no other write happens until the modified value is written back. - compare_
exchange_ bigint - The static
Atomics.compareExchange()
method exchanges a given replacement value at a given position in the array, if a given expected value equals the old value. It returns the old value at that position whether it was equal to the expected value or not. This atomic operation guarantees that no other write happens until the modified value is written back. - exchange
- The static
Atomics.exchange()
method stores a given value at a given position in the array and returns the old value at that position. This atomic operation guarantees that no other write happens until the modified value is written back. - exchange_
bigint - The static
Atomics.exchange()
method stores a given value at a given position in the array and returns the old value at that position. This atomic operation guarantees that no other write happens until the modified value is written back. - is_
lock_ free - The static
Atomics.isLockFree()
method is used to determine whether to use locks or atomic operations. It returns true, if the given size is one of theBYTES_PER_ELEMENT
property of integerTypedArray
types. - load
- The static
Atomics.load()
method returns a value at a given position in the array. - load_
bigint - The static
Atomics.load()
method returns a value at a given position in the array. - notify
- The static
Atomics.notify()
method notifies up some agents that are sleeping in the wait queue. Note: This operation works with a sharedInt32Array
only. Ifcount
is not provided, notifies all the agents in the queue. - notify_
with_ count - Notifies up to
count
agents in the wait queue. - or
- The static
Atomics.or()
method computes a bitwise OR with a given value at a given position in the array, and returns the old value at that position. This atomic operation guarantees that no other write happens until the modified value is written back. - or_
bigint - The static
Atomics.or()
method computes a bitwise OR with a given value at a given position in the array, and returns the old value at that position. This atomic operation guarantees that no other write happens until the modified value is written back. - store
- The static
Atomics.store()
method stores a given value at the given position in the array and returns that value. - store_
bigint - The static
Atomics.store()
method stores a given value at the given position in the array and returns that value. - sub
- The static
Atomics.sub()
method subtracts a given value at a given position in the array and returns the old value at that position. This atomic operation guarantees that no other write happens until the modified value is written back. - sub_
bigint - The static
Atomics.sub()
method subtracts a given value at a given position in the array and returns the old value at that position. This atomic operation guarantees that no other write happens until the modified value is written back. - wait
- The static
Atomics.wait()
method verifies that a given position in anInt32Array
still contains a given value and if so sleeps, awaiting a wakeup or a timeout. It returns a string which is either “ok”, “not-equal”, or “timed-out”. Note: This operation only works with a sharedInt32Array
and may not be allowed on the main thread. - wait_
async - The static
Atomics.waitAsync()
method verifies that a given position in anInt32Array
still contains a given value and if so sleeps, awaiting a wakeup or a timeout. It returns an object with two properties. The first propertyasync
is a boolean which if true indicates that the second propertyvalue
is a promise. Ifasync
is false then value is a string whether equal to either “not-equal” or “timed-out”. Note: This operation only works with a sharedInt32Array
and may be used on the main thread. - wait_
async_ bigint - The static
Atomics.waitAsync()
method verifies that a given position in anInt32Array
still contains a given value and if so sleeps, awaiting a wakeup or a timeout. It returns an object with two properties. The first propertyasync
is a boolean which if true indicates that the second propertyvalue
is a promise. Ifasync
is false then value is a string whether equal to either “not-equal” or “timed-out”. Note: This operation only works with a sharedBigInt64Array
and may be used on the main thread. - wait_
async_ with_ timeout - Like
waitAsync()
, but with timeout - wait_
async_ with_ timeout_ bigint - Like
waitAsync()
, but with timeout - wait_
bigint - The static
Atomics.wait()
method verifies that a given position in anBigInt64Array
still contains a given value and if so sleeps, awaiting a wakeup or a timeout. It returns a string which is either “ok”, “not-equal”, or “timed-out”. Note: This operation only works with a sharedBigInt64Array
and may not be allowed on the main thread. - wait_
with_ timeout - Like
wait()
, but with timeout - wait_
with_ timeout_ bigint - Like
wait()
, but with timeout - xor
- The static
Atomics.xor()
method computes a bitwise XOR with a given value at a given position in the array, and returns the old value at that position. This atomic operation guarantees that no other write happens until the modified value is written back. - xor_
bigint - The static
Atomics.xor()
method computes a bitwise XOR with a given value at a given position in the array, and returns the old value at that position. This atomic operation guarantees that no other write happens until the modified value is written back.