Skip to content

Add multi-threaded tests for acquire/release atomics - #8999

Merged
stevenfontanella merged 5 commits into
mainfrom
relaxed-atomics-execution
Aug 15, 2026
Merged

Add multi-threaded tests for acquire/release atomics#8999
stevenfontanella merged 5 commits into
mainfrom
relaxed-atomics-execution

Conversation

@stevenfontanella

@stevenfontanella stevenfontanella commented Aug 12, 2026

Copy link
Copy Markdown
Member
  • Add multi-threaded execution tests exercising acquire/release atomics
    • Most tests demonstrate at least one possible result that would not be possible with seqcst. It's impossible to write a test that would fail on an engine that implements acqrel using seqcst, since strengthening an atomic operation is always sound.
    • (atomic.fence acqrel) currently can't be exercised in a way that's correct without being completely redundant alongside another acqrel load/store. With a relaxed memory ordering the test would make more sense.
  • Invoke the pause instruction in the basic.wast test which was previously unexercised
  • In support.split_wast, ensure that (thread ...) and (wait ...) expressions are captured in the split output (the latter is currently a no-op anyway but best to include it for readability and correctness).
  • Rename relaxed_atomic_execution_tests -> acquire_release_atomics_execution_tests to match the new proposal name
  • The new tests pass in Binaryen's interpreter in an uninteresting way because (thread) blocks always run sequentially in a blocking manner.

@stevenfontanella
stevenfontanella force-pushed the relaxed-atomics-execution branch from b28920c to b9ded3f Compare August 12, 2026 23:34
@stevenfontanella
stevenfontanella marked this pull request as ready for review August 12, 2026 23:42
@stevenfontanella
stevenfontanella requested a review from a team as a code owner August 12, 2026 23:42
@stevenfontanella
stevenfontanella requested review from kripken, rmahdav and tlively and removed request for a team and kripken August 12, 2026 23:42
;; 1, 3 is only possible with acqrel, while others are also possible with
;; seqcst.
(assert_return (invoke "check")
(either (i32.const 1) (i32.const 4))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to express "either (1, 2) or (3, 4) or (2, 4)" with the either construct? Or would you have to write test code to explicitly check that kind of condition?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we would have to write test code. We can't have either of a product, instead it has to be a product of eithers like I have here:

Image

Are you asking for testing seqcst?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I was having trouble understanding how to read this because I would have expected either to be more powerful. It's fine for this case, but it would be useful to have more expressive power for the seqcst case.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave it for now, and if we have a seqcst test in the future it might make more sense to make both into a check function.

Comment thread test/spec/acquire-release-atomics/threaded.wast Outdated
Comment thread scripts/test/acquire_release_atomics_execution_tests.py
Comment thread test/spec/acquire-release-atomics/threaded.wast Outdated
Comment thread test/spec/acquire-release-atomics/threaded.wast Outdated
Comment on lines +207 to +215
(func $lock
(loop $spin
(if (i32.eqz (i32.atomic.rmw.cmpxchg acqrel (i32.const 0) (i32.const 0) (i32.const 1)))
(then (return))
)
(pause)
(br $spin)
)
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's awfully inconvenient to have to repeat so much of the module contents on each thread! It might be worth going back and adding some richer .wast infrastructure either in the original threads repo or as part of the acquire-release proposal.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked into this and one potential solution is the (module definition ...) and (module instance ...) syntax from the upstream spec interpreter (example). I think we would have one module that exports the shared memory, then a module definition that imports the shared memory and exports functions for the spinlock, then each threads instantiates the second module separately.

But I think we should wait on this solution, since the threads repo (and thus the acquire-release-atomics repo) is behind the upstream spec and doesn't support this syntax, so we wouldn't be able to run this on the spec interpreter. I'd suggest that we keep it this way and simplify the test once the threads + acquire-release-atomics interpreter have support for this syntax.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me 👍

Comment thread test/spec/acquire-release-atomics/threaded.wast Outdated
Comment thread test/spec/acquire-release-atomics/threaded.wast
Comment on lines +207 to +215
(func $lock
(loop $spin
(if (i32.eqz (i32.atomic.rmw.cmpxchg acqrel (i32.const 0) (i32.const 0) (i32.const 1)))
(then (return))
)
(pause)
(br $spin)
)
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me 👍

@stevenfontanella
stevenfontanella enabled auto-merge (squash) August 15, 2026 03:49
@stevenfontanella
stevenfontanella merged commit 8d9412e into main Aug 15, 2026
16 checks passed
@stevenfontanella
stevenfontanella deleted the relaxed-atomics-execution branch August 15, 2026 04:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants