mirror of
				https://github.com/tc39/test262.git
				synced 2025-10-31 19:53:50 +01:00 
			
		
		
		
	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,14 +19,18 @@ 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 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)); | ||||
|         while (Atomics.load(i32a, ${SPIN + i}) === 0) { | ||||
|           /* nothing */ | ||||
|         } | ||||
|         $262.agent.report(${i}); | ||||
|         Atomics.wait(i32a, ${WAKEUP}, 0); | ||||
|         $262.agent.report(${i}); | ||||
|         $262.agent.leaving(); | ||||
|       }); | ||||
|     `);
 | ||||
| @ -45,14 +49,29 @@ waitUntil(i32a, RUNNING, NUMAGENT); | ||||
|   // 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); | ||||
|   $262.agent.sleep(50); | ||||
| } | ||||
|   var waiterlist = []; | ||||
|   assert.sameValue(Atomics.store(i32a, SPIN + 0, 1), 1); | ||||
|   waiterlist.push(getReport()); | ||||
| 
 | ||||
| // 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"'); | ||||
|   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…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user