How to achieve parallelism for SharedArrayBuffer and Atomics?

ECMA 2017 (ES8), which just finished about a month ago, presents SharedArrayBuffer and Atomics . The link here shows that they are supported in some browsers.

As we know, they are designed to share data across streams. I wonder how this kind of parallelism is achieved in browsers and Node? Should we use Web Workers and the cluster package, respectively?

+4
source share
1 answer

Indeed, SharedArrayBuffersthey Atomicsare intended for use with browsers with WebWorkers , which is a natural way to have code executed in parallel threads in a browser context.

For Node.js, the threads generated by the cluster package will indeed be candidates for data exchange, but at the time of writing, there is no implementationSharedArrayBuffers in Node.js so far, so that's a theory. You can view a few discussions about this:

There is already an ems package that allows you to exchange data between different threads and processes.

on this topic:

+3

Source: https://habr.com/ru/post/1681934/


All Articles