-
Notifications
You must be signed in to change notification settings - Fork 17.6k
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/go_mem: "hello, world" will not always be printed twice #33815
Comments
You need some kind of synchronization like a channel or Quoting https://golang.org/ref/spec#Program_execution
|
Yes, of course. But the problem is with the documentation that states printing twice happens without any mention of a synchronization method. var a string
var once sync.Once
func setup() {
a += "hello, world" //change: to show that it doesn't run twice
}
func doprint(done chan int) {
once.Do(setup)
print(a)
done <- 1
}
func twoprint() {
var done = make(chan int) //change: synchronization
go doprint(done)
go doprint(done)
<-done
<-done
} |
You assumed a particular |
On the one hand, the missing On the other hand, the document is full of interesting details already — and adding that detail to one example implies that we would need to add it to the other examples, obscuring the more important point about the specific synchronization mechanism that is the focus of the example. Is there a way to make the examples more correct without making them substantially more verbose? |
See previously #27808. |
@bcmills I think changing the sentence to something like: |
It seems like the referenced doc is misleading:
go/doc/go_mem.html
Line 425 in 66ff373
What did you do?
What did you expect to see?
The result will be that "hello, world" will be printed twice.
What did you see instead?
Sometimes it was printed twice, and sometimes it was not printed at all.
System details
The text was updated successfully, but these errors were encountered: