JavaScript Atomics Object
Atomics provides operations that read and change shared memory safely when several threads, such as web workers, use the same SharedArrayBuffer.
Description
The Atomics object is a namespace of atomic operations on integer typed arrays, usually backed by a SharedArrayBuffer. An atomic operation completes in one step, so another thread can't see or interfere with a half-finished change. Methods include add(), sub(), load(), store(), exchange() and compareExchange().
Atomics.wait() and Atomics.notify() let workers sleep until another thread signals them. wait() isn't allowed on the browser's main thread; use Atomics.waitAsync() there instead.
Atomic operations only work on integer typed arrays, such as Int32Array and BigInt64Array, and are mostly meaningful when the array's buffer is shared. They're also used to implement locks, where only one worker at a time may enter a critical section of code. Shared memory and atomics are advanced tools; most web applications communicate between threads by passing messages instead.
Syntax
Atomics.add(typedArray, index, value)
Atomics.load(typedArray, index)
Atomics.wait(typedArray, index, value)Example
Browser Support
The following information will show you the current browser support for the Atomics object. Hover over a browser icon to see the version that first introduced support for this object.
Desktop





Tablets & Mobile





