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
Variable escapes to the heap when passed to sync/atomic function #31509
Comments
We could fix this by annotating those functions as non-escaping. Why is this an issue, though? There's no reason to be using atomic operations on the stack. That memory is not accessible by more than one thread. If anything, maybe this issue should be "replace sync/atomic operations on stack variables with regular loads and stores"? (Kinda half joking, but the motivation here escapes me.) Is there a library or something that is using these operations, that you want to call using the address of a stack object? It's unclear to me from your example what that might be. |
@randall77 thanks for your reply. This was an example intended to show to myself that mid stack inlining and atomic intrinsics reduce the final output of counter.inc (for example) to a locked xaddq. The only weird thing was the call to newobject to push c onto the heap. But you're right that theres no value in using atomics on stack variables; as you highlight, the memory is not shared with another thread. Taking a trip through |
Dup of #31509 ? |
That's this one. |
The routines in runtime/internal/atomic are already marked as I'd still like to see a real-world case where this would be worth fixing. |
Duplicate of #16241. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What did you do?
What did you expect to see?
c
does not escape the scope off()
What did you see instead?
The text was updated successfully, but these errors were encountered: