Chong Lip Phang Chong Lip Phang - 3 years ago 214
Javascript Question

How to achieve parallelism for SharedArrayBuffer and Atomics?

ECMA-2017(ES8), just finalized about a month ago, introduces SharedArrayBuffer and Atomics. The link here shows that they have been supported in some browsers.

As we know, they are meant to allow the sharing of data across threads. I wonder how this kind of parallelism is achieved in browsers and Node? Are we supposed to use Web Workers and the 'cluster' package respectively?

Answer Source

Indeed, for browsers SharedArrayBuffers and Atomics are intended to be used with WebWorkers, which is the natural way to have code run in concurrent threads in a browser context.

For Node.js, the threads spawned with the cluster package would indeed be candidates for sharing data, but at the time of writing there is no implementation of SharedArrayBuffers in Node.js yet, so this is theory. You may want to scan several discussions about it:

There already is the ems package which allows sharing data between different threads and processes.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download