WebAssembly / WebAssembly/threads
Behavior of `t.atomic.rmw.cmpxchg` instructions
Nobody has claimed this yet.
- Dominant language
- WebAssembly
- Stars
- 767
- Forks
- 54
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
As the 17. and 18. steps in the spec:
17. If c1 equals c2, then:
Let c be c2.
18. Else:
Let c be c3.
And the 21. step will write the c back to the memory.
Where c1 is the origin value on the memory, c2 is the expected value, c3 is the value to replace.
Maybe I can realize this as following simply:
if (memory[addr] != expected)
memory[addr] = replacement;
But the closest function in C++ std::atomic<T>::compare_exchange_strong has the different behavior.
if (memory[addr] == expected)
memory[addr] = replacement;
The atomic_rmw instructions are similar to the member functions of std::atomic<T> in C++ STL, such as fetch_add(), fetch_xor, etc.
Is it necessary to have the same behavior between cmpxchg instructions and std::atomic<T>::compare_exchange_strong in C++?
Thanks.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with steps 17–21 of the linked WebAssembly threads specification and compare their t.atomic.rmw.cmpxchg semantics with C++ std::atomic<T>::compare_exchange_strong. No repository files or tests are identified; done would require resolving whether the specified behavior is intentional and determining any resulting specification change.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- wasm
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100