notify-all.js (1877B)
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) 2017 Mozilla Corporation. All rights reserved. 3 // This code is governed by the BSD license found in the LICENSE file. 4 5 /*--- 6 esid: sec-atomics.notify 7 description: > 8 Test that Atomics.notify notifies all waiters if that's what the count is. 9 includes: [atomicsHelper.js] 10 features: [Atomics, SharedArrayBuffer, TypedArray] 11 ---*/ 12 13 const WAIT_INDEX = 0; // Waiters on this will be woken 14 const RUNNING = 1; // Accounting of live agents 15 const NUMAGENT = 3; 16 const BUFFER_SIZE = 4; 17 18 for (var i = 0; i < NUMAGENT; i++) { 19 $262.agent.start(` 20 $262.agent.receiveBroadcast(function(sab) { 21 const i32a = new Int32Array(sab); 22 Atomics.add(i32a, ${RUNNING}, 1); 23 24 $262.agent.report("A " + Atomics.wait(i32a, ${WAIT_INDEX}, 0)); 25 $262.agent.leaving(); 26 }); 27 `); 28 } 29 30 const i32a = new Int32Array( 31 new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * BUFFER_SIZE) 32 ); 33 34 $262.agent.safeBroadcast(i32a); 35 36 // Wait for agents to be running. 37 $262.agent.waitUntil(i32a, RUNNING, NUMAGENT); 38 39 // Try to yield control to ensure the agent actually started to wait. If we 40 // don't, we risk sending the notification before agents are sleeping, and we hang. 41 $262.agent.tryYield(); 42 43 // Notify all waiting on WAIT_INDEX, should be 3 always, they won't time out. 44 assert.sameValue( 45 Atomics.notify(i32a, WAIT_INDEX), 46 NUMAGENT, 47 'Atomics.notify(i32a, WAIT_INDEX) returns the value of `NUMAGENT`' 48 ); 49 50 for (var i = 0; i < NUMAGENT; i++) { 51 assert.sameValue($262.agent.getReport(), 'A ok', 'The value of reports[i] is "A ok"'); 52 } 53 54 reportCompare(0, 0);