Commit 70a0baaa authored by Leszek Swirski's avatar Leszek Swirski Committed by V8 LUCI CQ

[test] Robustify wait in regress-bug-9161

mjsunit/regress/regress-crbug-9161 had two spinlocks on an atomic:

  1. WaitUntil(lock == kStageRunning)
  2. WaitUntil(lock == kStageDone)

But, in theory the worker updating the "lock" could progress all the way
to kStageDone before the first loop manages to check the lock value
again.

We can make this more robust by checking:

  1. WaitUntil(lock != kStageInit)
  2. WaitUntil(lock == kStageDone)

That way both loops check for _any_ state past the state they want to
progress past.

Bug: v8:11437
Change-Id: I5220e61070a305301c678928edb0925c04dae970
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3231339
Auto-Submit: Leszek Swirski <leszeks@chromium.org>
Commit-Queue: Shu-yu Guo <syg@chromium.org>
Reviewed-by: 's avatarShu-yu Guo <syg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77460}
parent a20499e0
......@@ -20,10 +20,10 @@ const kStageDone = 2;
Atomics.store(lock, kStageIndex, kStageInit);
function WaitUntil(expected) {
function WaitUntil(funcOfValue) {
while (true) {
const value = Atomics.load(lock, kStageIndex);
if (value === expected) break;
if (funcOfValue(value)) break;
}
}
......@@ -49,11 +49,11 @@ const i32a = new Int32Array(
);
worker.postMessage([i32a.buffer, lock]);
WaitUntil(kStageRunning);
WaitUntil(value => value !== kStageInit);
for (let i = 0; i < kIterations; ++i) {
i32a.sort();
}
WaitUntil(kStageDone);
WaitUntil(value => value === kStageDone);
assertEquals(worker.getMessage(), "done");
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment