1 of 7

Shu-yu Guo (Google)

Lars Hansen (Mozilla)

Atomics.waitAsync

for Stage 3

2 of 7

Recap

Atomics.waitAsync(TA,idx,v,t)

If TA[idx] != v, return a promised resolved to “not-equal”.

Else returns a promise that is resolved either when

An agent calls Atomics.notify(TA,idx,c); resolved with “ok”.

Timeout expires; resolved with “timed-out”.

3 of 7

Fairness: Single FIFO Queue

  • No more line jumping for Atomics.wait
  • Single FIFO waiter queue per SAB location, just like now

4 of 7

Motivating Anomaly

let p1 = Atomics.waitAsync(i32a,0,v);

let p2 = Atomics.waitAsync(i32a,0,v);

Atomics.wait(i32a,0,v);

Resolving p1 and p2 don’t do anything useful if the agent is blocked!

5 of 7

But We Can’t Solve the General Problem

let p1 = Atomics.waitAsync(i32a,0,v);

let p2 = Atomics.waitAsync(i32a,0,v);

Atomics.wait(i32a,1,v);

Wrong trade off to solve the very narrow same-location case

6 of 7

Single FIFO Queue Implications

  • Allows the programmer to resolve Promises in agents that are blocked
  • Easy to reason about the order of Promise settlements and agent wake-ups
  • Trivially fair
  • PR #20

7 of 7

Stage 3?