New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sync/atomic: Load and Store don't use exclusive mode assembly instructions in arm64 weak memory model #35673
Comments
Thank you for this report @WangLeonard! Kindly pinging @cherrymui @randall77. |
Thanks @WangLeonard and @odeke-em. /cc @4ad, who I believe this was authored a good portion of this in golang.org/cl/7142. If you can't provide an example of failing code, could you please provide more details about the failure you encountered? |
Current go documentation does not specify any memory order guarantees made by the atomic operations, but there is some agreements on the memory order. Please refer to this CL https://go-review.googlesource.com/c/go/+/189417/ and this discussion https://groups.google.com/forum/#!msg/golang-dev/vVkH_9fl1D8/azJa10lkAwAJ. The reason why CAS uses exclusive mode Load/Store instructions is to guarantee multiple opeations of a single process are atomic accesses. But there is no obvious reason that we have to use exclusive load/store instructions for atomic Load/Store. Can you help to check your code to confirm whether it follows the rule "you shouldn't mix atomic and non-atomic accesses for a given memory word."? By the way, we also don't guarantee the memory order among atomic and non-atomic access on different memory. Additional notes: The following is a description of these instructions in the arm architecture reference manual. |
|
@toothrot @zhangfannie I added some positioning and found that when there is a problem with the application, |
I can't reproduce at Go1.13.1
|
@mengzhuo |
@WangLeonard what is the problem?
Why? It could be that the atomic store succeeded, then the CAS in wrap1 succeeded, but the scheduler hasn't woken the wrap2 goroutine. |
I want to mention that GCC also generates LDAR/STLR for atomic load/store.
|
@cherrymui For what you said the scheduler hasn't woken the wrap2 goroutine. So I guess When I can reproduce the problem or locate other reasons, I will provide more information. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Maybe,I have not verified.
What operating system and processor architecture are you using (
go env
)?go env
OutputIf there are any special considerations?
Load and Store use non-exclusive mode instructions
LDARW
,LDAR
,STLRW
,STLR
,instead of using exclusive mode instructions
LDAXRW
,STLXRW
like CAS.The store in amd64 also uses the exclusive
XCHGL
.In my application on arm64,
atomic.StoreInt32()
may have failed.But I don't have a simple demo to reproduce it now.
I want to ask if there are any special considerations?
Waiting for your reply urgently.
Thank you !
The text was updated successfully, but these errors were encountered: