11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_cirequire('../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ciconst { Worker } = require('worker_threads'); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ci// Make sure that allocating uninitialized ArrayBuffers in one thread does not 71cb0ef41Sopenharmony_ci// affect the zero-initialization in other threads. 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ciconst w = new Worker(` 101cb0ef41Sopenharmony_ciconst { parentPort } = require('worker_threads'); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_cifunction post() { 131cb0ef41Sopenharmony_ci const uint32array = new Uint32Array(64); 141cb0ef41Sopenharmony_ci parentPort.postMessage(uint32array.reduce((a, b) => a + b)); 151cb0ef41Sopenharmony_ci} 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_cisetInterval(post, 0); 181cb0ef41Sopenharmony_ci`, { eval: true }); 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_cifunction allocBuffers() { 211cb0ef41Sopenharmony_ci Buffer.allocUnsafe(32 * 1024 * 1024); 221cb0ef41Sopenharmony_ci} 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ciconst interval = setInterval(allocBuffers, 0); 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_cilet messages = 0; 271cb0ef41Sopenharmony_ciw.on('message', (sum) => { 281cb0ef41Sopenharmony_ci assert.strictEqual(sum, 0); 291cb0ef41Sopenharmony_ci if (messages++ === 100) { 301cb0ef41Sopenharmony_ci clearInterval(interval); 311cb0ef41Sopenharmony_ci w.terminate(); 321cb0ef41Sopenharmony_ci } 331cb0ef41Sopenharmony_ci}); 34