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-06-27 17:13:23 +02:00
|
|
|
const lapse = $262.agent.getReport();
|
2018-04-26 20:18:15 +02:00
|
|
|
assert(
|
2018-05-19 02:36:09 +02:00
|
|
|
lapse >= TIMEOUT,
|
2018-06-27 18:58:02 +02:00
|
|
|
'The result of `(lapse >= TIMEOUT)` is true (The result of `(lapse >= TIMEOUT)` is true)'
|
2018-04-26 20:18:15 +02:00
|
|
|
);
|
2018-06-27 18:58:02 +02:00
|
|
|
assert.sameValue(
|
|
|
|
$262.agent.getReport(),
|
|
|
|
'timed-out',
|
|
|
|
'$262.agent.getReport() returns "timed-out"'
|
|
|
|
);
|
|
|
|
assert.sameValue(Atomics.wake(i32a, 0), 0, 'Atomics.wake(i32a, 0) returns 0');
|
2018-04-26 17:16:34 +02:00
|
|
|
|