Complete the code to create a SharedArrayBuffer of 1024 bytes.
const sharedBuffer = new [1](1024);
The SharedArrayBuffer constructor creates a buffer that can be shared between threads.
Complete the code to create a typed array view over the shared buffer.
const sharedArray = new [1](sharedBuffer);Uint8Array creates a typed array view over the buffer, allowing byte-level access.
Fix the error in the code to safely increment a shared counter using Atomics.
Atomics.[1](sharedArray, 0, 1);
Atomics.add safely adds a value to the shared array at the given index.
Fill both blanks to create a shared buffer and a typed array view of 32-bit integers.
const buffer = new [1](128); const intArray = new [2](buffer);
Use SharedArrayBuffer to create shared memory and Int32Array to view it as 32-bit integers.
Fill all three blanks to atomically compare and exchange a value in the shared array.
const oldValue = Atomics.[1](sharedArray, [2], [3], 42);
Atomics.compareExchange compares the value at index 0 with 41, and if equal, replaces it with 42.