mirror of https://github.com/tc39/test262.git
Atomics: wake/wake-in-order.js, capture waiterlist order for wake comparison
This commit is contained in:
parent
fc4a6f12cb
commit
73be21272d
|
@ -36,13 +36,11 @@ function getReport() {
|
|||
* @param {Number} expected The number of agents that are expected to report as active.
|
||||
*/
|
||||
function waitUntil(i32a, index, expected) {
|
||||
var i = 0;
|
||||
while (Atomics.load(i32a, index) !== expected && i < 15) {
|
||||
$262.agent.sleep(10);
|
||||
i++;
|
||||
while (Atomics.load(i32a, index) !== expected) {
|
||||
/* nothing */
|
||||
}
|
||||
const agents = Atomics.load(i32a, index);
|
||||
assert.sameValue(agents, expected , `'agents' equals the value of expected (${expected })`);
|
||||
assert.sameValue(agents, expected, `'agents' equals the value of 'expected' (${expected})`);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -19,40 +19,59 @@ const NUMELEM = RUNNING + 1;
|
|||
// them go into a wait, thus controlling the waiting order. Then we wake them
|
||||
// one by one and observe the wakeup order.
|
||||
|
||||
for (var i = 0; i < NUMAGENT; i++) {
|
||||
$262.agent.start(`
|
||||
$262.agent.receiveBroadcast(function(sab) {
|
||||
const i32a = new Int32Array(sab);
|
||||
Atomics.add(i32a, ${RUNNING}, 1);
|
||||
while (Atomics.load(i32a, ${SPIN + i}) === 0)
|
||||
/* nothing */ ;
|
||||
$262.agent.report(${i} + Atomics.wait(i32a, ${WAKEUP}, 0));
|
||||
$262.agent.leaving();
|
||||
});
|
||||
`);
|
||||
}
|
||||
for (var attempt = 0; attempt < 10; attempt++) {
|
||||
for (var i = 0; i < NUMAGENT; i++) {
|
||||
$262.agent.start(`
|
||||
$262.agent.receiveBroadcast(function(sab) {
|
||||
const i32a = new Int32Array(sab);
|
||||
Atomics.add(i32a, ${RUNNING}, 1);
|
||||
while (Atomics.load(i32a, ${SPIN + i}) === 0) {
|
||||
/* nothing */
|
||||
}
|
||||
$262.agent.report(${i});
|
||||
Atomics.wait(i32a, ${WAKEUP}, 0);
|
||||
$262.agent.report(${i});
|
||||
$262.agent.leaving();
|
||||
});
|
||||
`);
|
||||
}
|
||||
|
||||
const i32a = new Int32Array(
|
||||
new SharedArrayBuffer(NUMELEM * Int32Array.BYTES_PER_ELEMENT)
|
||||
);
|
||||
const i32a = new Int32Array(
|
||||
new SharedArrayBuffer(NUMELEM * Int32Array.BYTES_PER_ELEMENT)
|
||||
);
|
||||
|
||||
$262.agent.broadcast(i32a.buffer);
|
||||
$262.agent.broadcast(i32a.buffer);
|
||||
|
||||
// Wait for agents to be running.
|
||||
waitUntil(i32a, RUNNING, NUMAGENT);
|
||||
// Wait for agents to be running.
|
||||
waitUntil(i32a, RUNNING, NUMAGENT);
|
||||
|
||||
// Sleep to allow the agents a fair chance to wait. If we don't,
|
||||
// we risk sending the wakeup before agents are sleeping, and we hang.
|
||||
$262.agent.sleep(50);
|
||||
|
||||
// Make them sleep in order 0 1 2 on i32a[0]
|
||||
for (var i = 0; i < NUMAGENT; i++) {
|
||||
Atomics.store(i32a, SPIN + i, 1);
|
||||
// Sleep to allow the agents a fair chance to wait. If we don't,
|
||||
// we risk sending the wakeup before agents are sleeping, and we hang.
|
||||
$262.agent.sleep(50);
|
||||
}
|
||||
|
||||
// Wake them up one at a time and check the order is 0 1 2
|
||||
for (var i = 0; i < NUMAGENT; i++) {
|
||||
assert.sameValue(Atomics.wake(i32a, WAKEUP, 1), 1, 'Atomics.wake(i32a, WAKEUP, 1) returns 1');
|
||||
assert.sameValue(getReport(), i + 'ok', 'getReport() returns i + "ok"');
|
||||
var waiterlist = [];
|
||||
assert.sameValue(Atomics.store(i32a, SPIN + 0, 1), 1);
|
||||
waiterlist.push(getReport());
|
||||
|
||||
assert.sameValue(Atomics.store(i32a, SPIN + 1, 1), 1);
|
||||
waiterlist.push(getReport());
|
||||
|
||||
assert.sameValue(Atomics.store(i32a, SPIN + 2, 1), 1);
|
||||
waiterlist.push(getReport());
|
||||
|
||||
var notified = [];
|
||||
assert.sameValue(Atomics.wake(i32a, WAKEUP, 1), 1);
|
||||
notified.push(getReport());
|
||||
|
||||
assert.sameValue(Atomics.wake(i32a, WAKEUP, 1), 1);
|
||||
notified.push(getReport());
|
||||
|
||||
assert.sameValue(Atomics.wake(i32a, WAKEUP, 1), 1);
|
||||
notified.push(getReport());
|
||||
|
||||
assert.sameValue(
|
||||
notified.join(''),
|
||||
waiterlist.join(''),
|
||||
`Attempt #${attempt}: notified and waiterlist order do not match.`
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue