Skip to content

Break it, then fix it

Drive the scheduler yourself until the program breaks its own invariant, name the ordering that was missing, and then repair it. A fix that wraps everything in one lock is correct and scores badly: the score is how much of the work can still overlap afterwards.

The cache that fills twice

Two requests arrive together, and both find the cache empty.

1function* handle(t) {2  const cached = yield t.load("cached");3 4  if (cached === 0) {5    const fresh = yield t.io("GET /expensive", 42);6    yield t.fetchAdd("calls", 1);7    yield t.store("cached", fresh);8  }9 10  const calls = yield t.load("calls");11  yield t.assert(calls <= 1, "the expensive call is made at most once");12}

Explained in The gap inside an await.

Everything you do here stays in this browser.