mirror of
https://github.com/nodejs/node.git
synced 2025-05-07 12:03:30 +00:00

Keep a reference to the `ArrayBuffer::Allocator` alive for at least as long as a `SharedArrayBuffer` allocated by it lives. Refs: https://github.com/nodejs/node/pull/28788 Fixes: https://github.com/nodejs/node/issues/28777 Fixes: https://github.com/nodejs/node/issues/28773 PR-URL: https://github.com/nodejs/node/pull/29190 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
34 lines
769 B
JavaScript
34 lines
769 B
JavaScript
'use strict';
|
|
require('../common');
|
|
const assert = require('assert');
|
|
const { Worker } = require('worker_threads');
|
|
|
|
// Make sure that allocating uninitialized ArrayBuffers in one thread does not
|
|
// affect the zero-initialization in other threads.
|
|
|
|
const w = new Worker(`
|
|
const { parentPort } = require('worker_threads');
|
|
|
|
function post() {
|
|
const uint32array = new Uint32Array(64);
|
|
parentPort.postMessage(uint32array.reduce((a, b) => a + b));
|
|
}
|
|
|
|
setInterval(post, 0);
|
|
`, { eval: true });
|
|
|
|
function allocBuffers() {
|
|
Buffer.allocUnsafe(32 * 1024 * 1024);
|
|
}
|
|
|
|
const interval = setInterval(allocBuffers, 0);
|
|
|
|
let messages = 0;
|
|
w.on('message', (sum) => {
|
|
assert.strictEqual(sum, 0);
|
|
if (messages++ === 100) {
|
|
clearInterval(interval);
|
|
w.terminate();
|
|
}
|
|
});
|