Next, create a SharedArrayBuffer that is of size ARRAY_SIZE, and create an Int32Array casting of it:
export function main() {
// ...
const sab = new SharedArrayBuffer(ARRAY_SIZE); const intBuffer = new Int32Array(sab);
}
Fill the intBufferwith random numbers between0andMAX_NUMBER:
export function main() {
// ...
// fill with random numbers // fill with random numbers intBuffer.forEach((value, index) => { intBuffer[index] = Math.random() * MAX_NUMBER; }); }
Calculate and print the sum of the values in the array:
export function main() {
// ...
// sum the ints const sum = intBuffer.reduce((acc, number) => acc + number , 0);
}
Start your Python web server and open the following link in your browser: http://localhost:8000/.