Skip to content
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

runtime: Is it necessary to use atomic.Loaduintptr on gp.stackguard0? #37880

Closed
Jerome-Tan opened this issue Mar 16, 2020 · 1 comment
Closed

runtime: Is it necessary to use atomic.Loaduintptr on gp.stackguard0? #37880

Jerome-Tan opened this issue Mar 16, 2020 · 1 comment

Comments

@Jerome-Tan
Copy link

@Jerome-Tan Jerome-Tan commented Mar 16, 2020

What version of Go are you using (go version)?

$ go version
go version go1.13.3 linux/amd64

Does this issue reproduce with the latest release?

It's not an issue, just curiosity.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

What did you do?

Reading the source code of runtime.

What did you expect to see?

Read/write operation on gp.stackguard0 does not require any atomic operations.

What did you see instead?

Atomic operations on gp.stackguard0 are used in only one place: runtime/stack.go.

func newstack() {
    ... ...
    // NOTE: stackguard0 may change underfoot, if another thread
    // is about to try to preempt gp. Read it just once and use that same
    // value now and below.
    preempt := atomic.Loaduintptr(&gp.stackguard0) == stackPreempt
    ... ...
}

If there is a data race, why not all use atomic operations?

@cagedmantis
Copy link
Contributor

@cagedmantis cagedmantis commented Mar 16, 2020

For asking questions about learning the language, see one of our forums: https://golang.org/wiki/Questions. We only use this issue tracker for tracking bugs. People in the forums can explain what is happening here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.