mirror of
https://github.com/golang/go
synced 2024-11-22 06:04:39 -07:00
faq: fix minor errors in programs reported by Wojciech Mikanik
R=golang-dev, rsc CC=golang-dev https://golang.org/cl/4114041
This commit is contained in:
parent
bba20fc1fa
commit
a64e63227a
@ -793,7 +793,7 @@ Consider the following program:
|
|||||||
func main() {
|
func main() {
|
||||||
done := make(chan bool)
|
done := make(chan bool)
|
||||||
|
|
||||||
values = []string{ "a", "b", "c" }
|
values := []string{ "a", "b", "c" }
|
||||||
for _, v := range values {
|
for _, v := range values {
|
||||||
go func() {
|
go func() {
|
||||||
fmt.Println(v)
|
fmt.Println(v)
|
||||||
@ -802,7 +802,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// wait for all goroutines to complete before exiting
|
// wait for all goroutines to complete before exiting
|
||||||
for i := range values {
|
for _ = range values {
|
||||||
<-done
|
<-done
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -823,7 +823,7 @@ could modify the inner loop to read:
|
|||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
for _, v := range values {
|
for _, v := range values {
|
||||||
go func(<b>u</b>) {
|
go func(<b>u</b> string) {
|
||||||
fmt.Println(<b>u</b>)
|
fmt.Println(<b>u</b>)
|
||||||
done <- true
|
done <- true
|
||||||
}(<b>v</b>)
|
}(<b>v</b>)
|
||||||
|
Loading…
Reference in New Issue
Block a user