2018-04-26 17:16:34 +02:00
|
|
|
// 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
|
2018-05-21 20:23:15 +02:00
|
|
|
includes: [atomicsHelper.js]
|
2018-04-26 20:11:31 +02:00
|
|
|
features: [Atomics, SharedArrayBuffer, TypedArray]
|
2018-04-26 17:16:34 +02:00
|
|
|
---*/
|
|
|
|
|
2018-06-25 21:17:45 +02:00
|
|
|
const TIMEOUT = 200;
|
2018-04-26 17:16:34 +02:00
|
|
|
const i32a = new Int32Array(
|
2018-06-25 21:17:45 +02:00
|
|
|
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)
|
2018-04-26 17:16:34 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$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);
|
2018-04-26 17:16:34 +02:00
|
|
|
$262.agent.leaving();
|
|
|
|
});
|
|
|
|
`);
|
|
|
|
|
|
|
|
$262.agent.broadcast(i32a.buffer);
|
2018-06-25 21:17:45 +02:00
|
|
|
$262.agent.sleep(10);
|
2018-04-26 20:18:15 +02:00
|
|
|
|
|
|
|
Atomics.exchange(i32a, 0, 1);
|
|
|
|
|
2018-05-19 02:36:09 +02:00
|
|
|
const lapse = getReport();
|
2018-04-26 20:18:15 +02:00
|
|
|
assert(
|
2018-05-19 02:36:09 +02:00
|
|
|
lapse >= TIMEOUT,
|
|
|
|
`${lapse} should be at least ${TIMEOUT}`
|
2018-04-26 20:18:15 +02:00
|
|
|
);
|
2018-05-19 02:36:09 +02:00
|
|
|
assert.sameValue(getReport(), 'timed-out');
|
|
|
|
assert.sameValue(Atomics.wake(i32a, 0), 0);
|
2018-04-26 17:16:34 +02:00
|
|
|
|