2021-05-06 10:29:20 +00:00
|
|
|
// Copyright 2021 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
const sync_arr = new Int32Array(new SharedArrayBuffer(4));
|
|
|
|
function waitForWorker() {
|
|
|
|
while (Atomics.load(sync_arr) == 0) {}
|
|
|
|
}
|
|
|
|
function onmessage([sab, lock]) {
|
|
|
|
const i32a = new Int32Array(sab);
|
|
|
|
Atomics.store(lock, 0, 1);
|
2021-05-06 13:00:41 +00:00
|
|
|
for (let j = 1; j < 1000; ++j) {
|
2021-05-06 10:29:20 +00:00
|
|
|
for (let i = 0; i < i32a.length; ++i) {
|
|
|
|
i32a[i] = j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const worker = new Worker(`onmessage = ${onmessage}`, {type: 'string'});
|
2021-05-06 13:00:41 +00:00
|
|
|
const arr =
|
|
|
|
new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 100));
|
2021-05-06 10:29:20 +00:00
|
|
|
worker.postMessage([arr.buffer, sync_arr]);
|
|
|
|
|
|
|
|
waitForWorker();
|
|
|
|
arr.sort();
|