Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 206
Chong Lip Phang Avatar asked Jul 21 '17 06:07

Chong Lip Phang


1 Answers

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:

  • Tracking issue: Worker support
  • Does NodeJS have any plans for shared memory?
  • High level architecture
  • Why is it so hard to add threads to nodejs? or web workers?

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

Related:

  • node-webworker-threads - Lightweight Web Worker API implementation with native threads
like image 73
trincot Avatar answered Sep 30 '22 15:09

trincot