How to do it...

  1. Open your command-line application and navigate to your workspace.
  2. Create a new folder named 05-08-use-atomics-to-coordinate.
  3. Copy or create an index.html that loads and runs a main function from main.js.
  1. Create a main.js file. Create three shared array buffers: an input buffer and two output buffers (one safe, the other unsafe). The output buffers should be 32 bits in size:
// main.jsconst NUMBER_COUNT = Math.pow(2, 10); const BYTES_FOR_32_BIT = 4;const ARRAY_SIZE = NUMBER_COUNT * BYTES_FOR_32_BIT; const sab = new SharedArrayBuffer(ARRAY_SIZE); const intBuffer = new Int32Array(sab); const outSab = new SharedArrayBuffer(BYTES_FOR_32_BIT); const unsafeSab = new SharedArrayBuffer(BYTES_FOR_32_BIT); const workerCount = 256; ...

Get ECMAScript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.