Atomics object provides atomic operations as static methods. They are used with
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).
When memory is shared, multiple threads can read and write the same data in memory. Atomic operations make sure that predictable values are written and read, that operations are finished before the next operation starts and that operations are not interrupted.
wake() methods are modeled on Linux futexes ("fast user-space mutex") and provide ways for waiting until a certain condition becomes true and are typically used as blocking constructs.
Verifies that a given position in the array still contains a given value and sleeps awaiting or times out. Returns either
"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).
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.
|ECMAScript Latest Draft (ECMA-262) |
The definition of 'Atomics' in that specification.
|Draft||Initial definition in ES2017.|
|Feature||Chrome||Firefox (Gecko)||Internet Explorer||Opera||Safari|
|Basic support||No support ||55 (55) ||No support||No support||No support|
|Feature||Android||Chrome for Android||Firefox Mobile (Gecko)||IE Mobile||Opera Mobile||Safari Mobile|
|Basic support||No support||No support||55.0 (55) ||No support||No support||No support|
 In Firefox version 46 until version 54, this feature is disabled by a preference setting. In about:config, set
 The implementation is under development and needs these runtime flags:
Prior to SpiderMonkey 48 (Firefox 48 / Thunderbird 48 / SeaMonkey 2.45), the latest API names and semantics weren't implemented yet. The changes between Firefox version 46 and version 48 are:
Atomics.fence()are now removed entirely (bug 1259544 and bug 1225028).
Atomics.futexWake()(bug 1260910). Note: The old names have been removed in version 49 and later (bug 1262062).
Atomics.NOTEQUALhave been removed. The
Atomics.wait()method now returns the strings "ok", "timed-out" and "not-equal" (bug 1260835).
© 2005–2017 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.