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

doc: About Golang memory model-The loop in main is not guaranteed to finish. #37645

Closed
nerored opened this issue Mar 4, 2020 · 2 comments
Closed
Labels
Documentation Issues describing a change to documentation. FrozenDueToAge

Comments

@nerored
Copy link

nerored commented Mar 4, 2020

Another incorrect idiom is busy waiting for a value, as in:

var a string
var done bool

func setup() {
	a = "hello, world"
	done = true
}

func main() {
	go setup()
	for !done {
	}
	print(a)
}

As before, there is no guarantee that, in main, observing the write to done implies observing the write to a, so this program could print an empty string too. Worse, there is no guarantee that the write to done will ever be observed by main, since there are no synchronization events between the two threads. The loop in main is not guaranteed to finish.

this code from https://golang.org/ref/mem#tmp_2

what is mean The loop in main is not guaranteed to finish?is only happens on single core cpu or all mulit core cpus.

I run test on it,the main is all always finish。

@nerored nerored changed the title About Golang memory model-The loop in main is not guaranteed to finish. doc: About Golang memory model-The loop in main is not guaranteed to finish. Mar 4, 2020
@gopherbot gopherbot added the Documentation Issues describing a change to documentation. label Mar 4, 2020
@randall77
Copy link
Contributor

"The loop in main is not guaranteed to finish" means exactly what is says.
Just because all of our current implementations of Go eventually exit this loop, doesn't mean that it is guaranteed to finish on all future implementations of Go.

You'll probably have better results asking questions like this in one of the forums listed at https://github.com/golang/go/wiki/Questions. Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

@nerored
Copy link
Author

nerored commented Mar 4, 2020

ok, thanks

@golang golang locked and limited conversation to collaborators Mar 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation Issues describing a change to documentation. FrozenDueToAge
Projects
None yet
Development

No branches or pull requests

3 participants