The ECMAScript specification defines the Atomics object in the section 24.4.
Among all the global objects this is the more obscure for
I have coded a script using Web Worker and SharedArrayBuffer to demonstrate the use of Atomics:
Then with a separate file worker.js:
// worker.js
onmessage = function(e) {
e.data[0]++; // last line is 981 only? wth?!
//Atomics.add(e.data,0,1); // last line is exactly 1000. right...
console.log(e.data[0]);
}
As you can see, without the mutex guaranteed by Atomics, the addition would not be correctly carried out sometimes.