no-spurious-wakeup-on-xor.js (1707B)
1 // |reftest| skip-if(!this.hasOwnProperty('Atomics')||!this.hasOwnProperty('SharedArrayBuffer')||(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration('arm64-simulator'))) -- Atomics,SharedArrayBuffer is not enabled unconditionally, ARM64 Simulator cannot emulate atomics 2 // Copyright (C) 2018 Rick Waldron. All rights reserved. 3 // This code is governed by the BSD license found in the LICENSE file. 4 5 /*--- 6 esid: sec-atomics.wait 7 description: > 8 Waiter does not spuriously notify on index which is subject to xor operation 9 includes: [atomicsHelper.js] 10 features: [Atomics, SharedArrayBuffer, TypedArray] 11 ---*/ 12 13 const RUNNING = 1; 14 const TIMEOUT = $262.agent.timeouts.small; 15 16 const i32a = new Int32Array( 17 new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4) 18 ); 19 20 $262.agent.start(` 21 $262.agent.receiveBroadcast(function(sab) { 22 const i32a = new Int32Array(sab); 23 Atomics.add(i32a, ${RUNNING}, 1); 24 25 const before = $262.agent.monotonicNow(); 26 const unpark = Atomics.wait(i32a, 0, 0, ${TIMEOUT}); 27 const duration = $262.agent.monotonicNow() - before; 28 29 $262.agent.report(duration); 30 $262.agent.report(unpark); 31 $262.agent.leaving(); 32 }); 33 `); 34 35 $262.agent.safeBroadcast(i32a); 36 $262.agent.waitUntil(i32a, RUNNING, 1); 37 38 // Try to yield control to ensure the agent actually started to wait. 39 $262.agent.tryYield(); 40 41 Atomics.xor(i32a, 0, 1); 42 43 const lapse = $262.agent.getReport(); 44 assert( 45 lapse >= TIMEOUT, 46 'The result of `(lapse >= TIMEOUT)` is true' 47 ); 48 assert.sameValue( 49 $262.agent.getReport(), 50 'timed-out', 51 '$262.agent.getReport() returns "timed-out"' 52 ); 53 assert.sameValue(Atomics.notify(i32a, 0), 0, 'Atomics.notify(i32a, 0) returns 0'); 54 55 reportCompare(0, 0);