test262/test/built-ins/Atomics/wait/no-spurious-wakeup-on-or.js

53 lines
1.3 KiB
JavaScript
Raw Normal View History

// Copyright (C) 2018 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-atomics.wait
description: >
Demonstrates that Atomics.store(...) is causing a waiting
features: [Atomics, SharedArrayBuffer, TypedArray]
---*/
function getReport() {
var r;
while ((r = $262.agent.getReport()) == null) {
$262.agent.sleep(10);
}
return r;
}
const TWO_SECOND_TIMEOUT = 2000;
const i32a = new Int32Array(
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)
);
$262.agent.start(`
$262.agent.receiveBroadcast(function(sab) {
var i32a = new Int32Array(sab);
$262.agent.report("ready");
2018-05-18 21:24:57 +02:00
var before = $262.agent.monotonicNow();
Atomics.wait(i32a, 0, 0, ${TWO_SECOND_TIMEOUT});
2018-05-17 20:06:22 +02:00
$262.agent.report($262.agent.monotonicNow() - before);
$262.agent.leaving();
});
`);
$262.agent.broadcast(i32a.buffer);
assert.sameValue(getReport(), "ready");
Atomics.or(i32a, 0, 1);
// We should expect that the waiting agents will continue to
// wait until they both timeout. If either of them reports
// a value that is less than the timeout value, it may mean that
// calling Atomics.store(...) is causing the agents to wake.
//
var lapse = getReport();
assert(
lapse >= TWO_SECOND_TIMEOUT,
`${lapse} should be at least ${TWO_SECOND_TIMEOUT}`
);