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

41 lines
1.0 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: >
2018-05-19 02:36:09 +02:00
Waiter does not spuriously wake on index which is subject to exchange operation
includes: [atomicsHelper.js]
features: [Atomics, SharedArrayBuffer, TypedArray]
---*/
2018-05-19 02:36:09 +02:00
const TIMEOUT = 2000;
const i32a = new Int32Array(
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)
);
$262.agent.start(`
$262.agent.receiveBroadcast(function(sab) {
2018-05-19 02:36:09 +02:00
const i32a = new Int32Array(sab);
const before = $262.agent.monotonicNow();
const unpark = Atomics.wait(i32a, 0, 0, ${TIMEOUT});
2018-05-17 20:06:22 +02:00
$262.agent.report($262.agent.monotonicNow() - before);
2018-05-19 02:36:09 +02:00
$262.agent.report(unpark);
$262.agent.leaving();
});
`);
$262.agent.broadcast(i32a.buffer);
2018-05-19 02:36:09 +02:00
$262.agent.sleep(100);
Atomics.exchange(i32a, 0, 1);
2018-05-19 02:36:09 +02:00
const lapse = getReport();
assert(
2018-05-19 02:36:09 +02:00
lapse >= TIMEOUT,
`${lapse} should be at least ${TIMEOUT}`
);
2018-05-19 02:36:09 +02:00
assert.sameValue(getReport(), 'timed-out');
assert.sameValue(Atomics.wake(i32a, 0), 0);