3 ms·
Javascript in browsers already has a full atomics API: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics https://develop
by slimsag 2y ago
Javascript in browsers already has a full atomics API:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
I'm not sure why Web Locks is useful TBH. I guess if you don't understand atomics it's a friendlier API?
- whilenot-dev 2y agoYou mean Atomics + SharedArrayBuffer, otherwise it won't be shared across agents. I can imagine all the postMessage calls and message handlers swirling around in all agents to approximate something like the Web Locks API for a simple lock, but tbh I'd take the Web Locks API any day.
- pavlov 2y agoThe Web Locks documentation explains that it works across tabs, i.e. separate processes: ”[…] allows a web app running in multiple tabs or workers to coordinate work and the use of resources” A locking API is much more natural and less error-prone for this use case than using shared memory and atomics.
- mrkeen 2y agoIt's "atomic" in the sense that it does one thing. It lets you do "actions", not "transactions". A transaction would allow you to do multiple things. If the atomics API gave you ability to do multiple things, you wouldn't need compareExchange, because you could just do compare and then exchange.